- 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
vimtutorin terminal to learn/practice! (80x24 terminal recommended) vim FILEopens 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
escreturns to normal mode (consider rebindingcaps locktoesc) - 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),:qato 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 nextCHARt/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 withCHARu= undo,ctrl-r= redoy= copy (”yank”), i.e.ywto 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