Vim 치트시트
쉬운 언어로 설명하는 Vim 명령어: 모드, 이동(motion), 연산자(operator), 찾기 및 바꾸기, 매크로와 설정. Vim 9.1에서 실행된 예제가 포함되어 있습니다.
동작 원리
Vim is modal: the same key does different things depending on the mode. Normal mode (the default) runs commands, Insert mode types text, Visual mode selects text and Command-line mode (the colon prompt) runs Ex commands. Most edits read like a sentence: an operator (d, c, y) plus a motion or text object (w, ip, i").
서바이벌 키트
가장 먼저 배워야 할 몇 가지 명령어입니다.
80개 명령어
Open, save & quit
If you ever feel lost, press Esc a couple of times: it always returns you to Normal mode, where the commands below work.
공식 문서: Starting Vim- 기본
Open a file in Vim.
vim <file>명령어 만들기
vim <file>값은 입력한 그대로 삽입됩니다. 공백이나 특수 문자가 포함된 경우 직접 따옴표로 감싸 주세요.
사용 시점
Starts editing an existing file, or a new one that is created the first time you save.
상세 분석
- vim
- the editor
- <file>
- path of the file to open (it need not exist yet)
예제
Opens notes.txt, or an empty buffer called notes.txt if the file does not exist.
vim notes.txt주의 사항
- Stuck? Press Esc, type :q! and press Enter to leave without saving.
참고
Move around
Learn motions first: every delete, change and yank command takes a motion, so moving well is the same skill as editing well.
공식 문서: Motion commandsType & fix text
Small edits you will do all day: start typing in the right place, remove or replace a character, undo, and repeat.
공식 문서: Inserting and changing textDelete, copy & change (operators)
Vim edits are sentences: operator + (count) + motion or text object. d = delete, c = change, y = yank (copy). Learn the verbs once and combine them with every noun.
공식 문서: Operators and text objectsSelect first, then act
Visual mode shows what you will affect before you press the operator. It is slower than a good motion but friendlier while you learn.
공식 문서: Visual modeSearch & replace
Searching is just another motion, so d/foo deletes up to the next foo. Search and substitute both use regular expressions.
공식 문서: Patterns and searchFiles, buffers, windows & tabs
A buffer is a file in memory, a window is a view of a buffer, and a tab page is a set of windows. You can have many buffers open without showing them all.
공식 문서: Windows, buffers and tab pagesMacros & registers
Registers are named clipboards: yanks and deletes go into them, and macros are keystrokes recorded into them.
공식 문서: RegistersSettings & your vimrc
Options are changed with :set and last until you quit. Put the ones you like in your vimrc so they apply every time.
공식 문서: Options and vimrcKitLocal 도구에서 사용해 보기
용어집
- Normal mode
- The default mode, where keys are commands. Press Esc to return here.
- Insert mode
- The mode where typed characters become text.
- Visual mode
- Select text with v, V or Ctrl-v, then apply an operator to it.
- Ex command
- A command typed after a colon, such as :w or :%s/a/b/g.
- Motion
- A command that moves the cursor (w, $, gg). Operators act on the text it covers.
- Operator
- A command that acts on text: d (delete), c (change), y (yank = copy), > (indent).
- Text object
- A region such as a word, quoted string or paragraph, chosen with i (inner) or a (around).
- Register
- A named storage slot for yanked or deleted text, like a clipboard with many slots.
- Buffer
- A file loaded in memory. A window shows a buffer; a tab page holds windows.