개발/오늘 배운 지식

[Vim + vscode] 단축키 모음(Vscode Vim Cheat Sheet)

Woogie2 2021. 10. 2. 19:25
반응형

다시 보기 위해 적는 vscode Vim extension 키 사용법.

VSCodeVim

Normal Mode

Motion

  • h 커서를 왼쪽으로
  • j 커서 아래로
  • k 커서 위로
  • l 커서 오른쪽으로
  • i Insert mode
  • <ESC> <Ctrl-C> <Ctrl-[> Go to Normal mode

단어별 이동

word는 괄호 문자 포함 X, WORD는 포함 O

  • w move to the beginning of next word
  • b move to the beginning of the previous word
  • e move to the end of the next word
  • ge move to the end of the previous word

  • W move to the beginning of next WORD
  • B move to the beginning of the previous WORD
  • E move to the end of the next WORD
  • gE move to the end of the previous WORD

알파벳 문자 하나 검색(하나의 코드 줄에서)

해당 문자로 커서 이동

  • f{character} Find next occurrence of character
  • F{character} Find previous occurrence of character

찾는 문자 하나 앞의 문자로 커서 이동

  • t{character} Find next occurrence of character and place cursor just before it
  • T{character} Find previous occurrence of character and place cursor just before it

다음 or 이전의 일치하는 문자로 이동

  • ; Go to next occurrence of {character}
  • , Go to previous occurrence of {character}

수평 방향으로 커서 이동(단일 줄에서)

줄의 앞과 끝

  • 0 Moves to the first character of a line
  • ^ Moves to the first non-blank character of a line
  • $ Moves to the end of a line
  • g_ Moves to the non-blank character at the end of a line

수직 방향으로 빠르게 이동하기

문단 단위 or 페이지 단위

  • } Jumps entire paragraphs downwards
  • { similarly but upwards
  • CTRL-D lets you move down half a page by scrolling the page
  • CTRL-U lets you move up half a page also by scrolling

검색 기능(하나의 파일 내에서 검색)

  • /{pattern} Search for {pattern}. {pattern} is a regex.
  • ?{pattern} Search for {pattern} backwards.

  • / Repeat last search forwards
  • ? Repeat last search backwards

  • n Go to next match
  • N Go to previous match

count를 활용해서 더욱 빠르게.

  • {count}{motion} Repeat {motion} {count} times

  • 2w Jump to second word
  • 4f" Jump to fourth occurrence of the " character
  • 3/cucumber Jump to third match of "cucumber"

Move Semantically

  • gd Go to definition (of the word under the cursor)
  • gf Go to file (for file under the cursor)

이외의 core motion들

  • gg Go to the top of the file
  • {line}gg Go to {line}
  • G Go to the end of the file
  • % jump to matching ({[]})

Operator

Edit with vim operators

  • {operator}{count}{motion} Apply operator on bit of text covered by motion

  • d delete
  • c change
  • y yank (copy)
  • p p (paste)
  • g~ switch case
  • > shift right
  • < shift left
  • = format

LineWise

  • dd delete a line
  • cc change a line
  • yy yank (copy) a line
  • g~~ switch case of a line
  • >> shift line right
  • << shift lineleft
  • == format line

Capital Case operator더 Strong한 ver

  • D delete from cursor to the end of the line
  • C change from cursor to the end of the line
  • Y yank (copy) a line. Like yy
  • P put (paste) before the cursor

text object와 operator

  • {operator}a{text-object} Apply operator to all text-object including trailing whitespace
  • {operator}i{text-object} Apply operator inside text-object

  • diw delete inner word
  • daw delete a word
  • dis delete inner sentence
  • das delete a sentence
  • dip delete inner paragraph
  • dap delete a paragraph
  • di(dib delete inside parentheses
  • da( dab delete text inside parentheses (including parentheses)
  • di{ diB delete inside braces
  • da{ daB delete text inside braces (including braces)
  • di[ delete inside brackets
  • da[ delete text inside brackets (including brackets)
  • di" delete inside quotes
  • da" delete a quoted text (including quotes)
  • dit delete inside tag
  • dat delete a tag (including tag)

  • ciw same goes for other operators...

Repeat Last Change

  • . Repeat the last change

문자 수정 커맨드

  • x delete a character. Like dl
  • X delete character before the cursor. Like dh
  • s change a character. Like cl
  • ~ switch case of a character

Undo, Redo

  • u Undo last change
  • Ctrl-R Redo last undo
  • {count}u undo last {count} changes

Insert Mode

  • i go into insert mode before the cursor
  • a go into insert mode after the cursor

  • I go into insert mode at the beginning of a line
  • A go into insert mode at the end of a line

  • o insert new line below current line and go into insert mode
  • O insert new line above current line and go into insert mode

  • gi go to the last place you left insert mode

  • Ctrl-H delete last character
  • Ctrl-W delete last word
  • Ctrl-U delete last line

Visual Mode

  • v go into character-wise visual mode
  • V go into line-wise visual mode
  • Ctrl-V go into block-wise visual mode (to select rectangular blocks of text)

  • {trigger visual mode}{motion}{operator} Visual mode operates in kind of the opposite way to normal mode.First you specify the motion to select text, and then you apply the operator

etc.

Operate on Next Search Match

  • {operator}gn Apply operator on next match
  • . After using {op}gn, the dot commant repeats the last change on the next match. Woooot!

복사 및 붙여넣기

  • y{motion} yank (copy) text covered by motion
  • p put (paste) after cursor
  • P paste before cursor

  • yy copy line
  • Y copy line

  • yyp duplicate line
  • ddp swap lines
  • xp swap characters

  • "ay{motion} copy to register a
  • "Ay{motion} copy and append to register a
  • "ap paste from register a

  • " unnamed register
  • 0 yank register
  • 1-9 delete registers
  • [a-z] named registers

  • Ctrl-R a paste from register a when in Insert mode

창 분할

  • :sp {file} Open file in a horizontal split
  • :vsp {file} Open file in a vertical split
  • Ctrl-W S Open same file in a horizontal split
  • Ctrl-W V Open same file in a vertical split
  • Ctrl-W h Move to split to the left
  • Ctrl-W j Move to split below
  • Ctrl-W k Move to split above
  • Ctrl-W l Move to split to the right

탭 열기

  • :tabnew {file} Open file in new tab
  • :tabnext:tabn Jump to next tab
  • :tabprev:tabp Jump to previous tab
  • :tabonly:tabo Close all other tabs

vim surround 관련 커맨드

  • ds delete surroundings (e.g.) ds"
  • cs change surroundings (e.g.) cs\*tem>
  • ys add surroundings (e.g.) ysiw"

  • ds" delete surrounding quotes
  • cs*tem> change surrounding * for the <em> tag
  • ysiw" surround word under the cursor with quotes

  • S In visual mode you can select some text, then type S to add surroundings. e.g. Stp> to wrap the selection in a <p> tag

Reference

Vscode Learn Vim Extension

반응형