- Vim is a modal editor - it has different modes
- Normal: moving around a file, editing
- Insert: inserting
- Replace: replacing
- Visual: selecting blocks of text
- Command-line: running a command like save, quit, etc.
- Run
vimtutor
in terminal to learn/practice! (80x24 terminal recommended) vim FILE
opens up the file- Vim maintains a set of open buffers (aka files), and on top of that you can have tabs and windows
- Switching modes
- Pressing
esc
returns to normal mode (consider rebindingcaps lock
toesc
) - From normal,
i
= insert mode,R
= replace,v
= visual,V
= visual line,^V
= visual block,:
= command-line
- Pressing
- Command-line mode:
:q
= quit (close window),:qa
to quit all open windows/tabs:w
= save (“write”):wq
= save and quit:e FILE
= open file to edit:help TOPIC
= get documentation on command (if you want help on a command-line command, type with colon, i.e.:q
)
- Movement, aka “nouns”
hjkl
= “arrow keys”w
= next “word”,b
= “beginning” of word,e
= “end” of word0
= beginning of line,^
= first non-blank char,$
= end of lineH
= “highest” line on screen,M
= “middle” line,L
= “lowest” linectrl-u
,ctrl-d
= scroll “up”/“down”gg
= beginning of file,G
= end of filef
/F
+CHAR
= (”find”) jump forward/backward to nextCHAR
t
/T
+CHAR
= (”to”) jump forward/backward right before nextCHAR
- Editing, aka “verbs”, which act on nouns
o
/O
= insert line above/below cursor + enter insert moded
+NOUN
= delete- e.g.
dw
= delete word,d$
= delete from cursor to end of line, etc.
- e.g.
c
+NOUN
= delete + enter insert modex
= delete character (same asdl
)r
+CHAR
= replace cursor character withCHAR
u
= undo,ctrl-r
= redoy
= copy (”yank”), i.e.yw
to copy word,p
= paste
- Visual
v
= select/highlight, navigate around to expandV
= highlights whole linectrl-v
= highlights “ blocks”
- Customization
- Change Vim’s behavior/configuration via
~/.vimrc
,- Example config file provided by course instructors
- Extensions also available
- ctrlp.vim: fuzzy file finder
- ack.vim: code search
- nerdtree: file explorer
- vim-easymotion: magic motions
- Change Vim’s behavior/configuration via
- A good rule: whenever you think “there must be a better way of doing this”, there probably is, and you can find it online