Notes : vim
Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems.
My vim dot files are available in my dotfiles project on GitHub.
Basic Usage
- Start vim with
vimorvim <filename>to edit a specific file. - Press
ito enter Insert Mode. - Type text.
- Press
escto enter Command Mode. - Type
:wqto write file and quit, or:q!to quit without saving.
Basic Commands
esc= enter command modei= enter insert mode:w= write file:wq= write file and quit vim:q!= quit without writing changes
Help Basics
:help= open help window:help <topic>= open help and jump to topicctrl-w w= jump between help/file windowsctrl-w q= close help window
Movement
Basic Movement
j= move cursor downk= move cursor uph= move cursor leftl= move cursor right
Character Movement
f<character>= move cursor to the next character in the current lineF<character>= move cursor to the previous character in the current linet<character>= move cursor before the next character in the current lineT<character>= move cursor after the previous character in the current line;= repeat last f, t, F or T,= repeat last f, t, F or T in opposite direction
Word Movement
w= jump to next word startb= jump to previous word starte= jump to next word endge= jump to previous word endW= jump to next whitespace-delimited word startB= jump to previous whitespace-delimited word startE= jump to next whitespace-delimited word endgE= jump to previous whitespace-delimited word end
Sentence Movement
)= move to next sentence start(= move to previous sentence start
Paragraph Movement
}= move to next paragraph start{= move to previous paragraph start
Line Movement
:<number>= jump to line number0= move to beginning of line^= jump to first non-black character of line$= move to end of lineH= jump to first line of screenM= jump to middle line of screenL= jump to last line of screenzt= make the current line the top of the windowzz= make the current line the middle of the windowzb= make the current line the bottom of the windowctrl-e= scroll screen one line upctrl-y= scroll screen one line down
Block Movement
%= move to closing compliment of character under cursor (open/close type items)
Page Movement
ctrl-f= jump one page downctrl-b= jump one page upctrl-d= jump half page downctrl-u= jump half page up
File Movement
gg= jump to start of fileG= Jump to end of file
Insertion
i= insert before cursora= insert after cursorI= insert at beginning of lineA= insert at end of lineo= append below current lineO= insert above current line
Replacement
r= replace single character~= switch case of charactercw= change from cursor to end of wordciw= change entire word cursor is inside ofc$orC= change to end of linecc= change entire linect<character>= change until characterR= enter replacement mode
Cut
x= cut character under cursorX= cut character before cursordw= cut current wordddor:d= cut line<number>dd= cut number lines"<letter>dd= cut line and create register named after letter"<LETTER>dd= cut line and append to register named after letter
Copy
yw= copy a wordy$= copy to end of lineyyorY= copy entire line<number>yy= copy number lines"<letter>yy= yank line and create register named after letter"<LETTER>yy= yank line and append to register named after letter
Paste
p= paste below cursorP= paste above cursor"<letter>p= paste text after cursor from buffer named after letter"<number>p= paste text after cursor from most recently deleted text
Undoing a numbered paste and then using the . command will paste from the next numbered buffer.
Registers
:reg= show contents of all registers:reg <letter|number>= show contents of
Selection
v= enter character selection modeV= enter line selection mode
Visual Mode Commands
>= shift right<= shift leftc= change highlighted texty= copy highlighted textd= cut highlighted text
Undo / Redo
u= undo last actionU= undo latest changes to current lineCtrl+r= redo
Search
/<pattern>= Search for patternn= search for next matchN= search for previous match
Search & Replace
:s/this/that/g= change all this to that in current line:s/this/that/gi= change all this to that in current line, case-insensitive:s/this/that/gic= change all this to that in current line, case-insensitive, ask for confirmation:%s/this/that/g= change all this to that in current file
Folding
za= fold/unfold current sectionzM= fold all sectionzR= unfold all sections
Files
:r <name>= insert file name below cursor:r !<command>= execute command and insert its output below cursor:forctrl-g= display file info in status line
Tabs
:tabnew <file>= open file in a new tab:tabs= list open tabs:tabclose= close current tab:tabonly= close all tabs but current:tabf<space><name>= search for file in current directory, open in new tab:tabnorgt= switch to next tab:tabporgT= switch to previous tab:tabfirst= switch to first tab:tablast= switch to last tab:tabm<number>= move current tab to tab position number (first tab is 0):tabdo <command>= run command across all open tabs
MacVim Tabbing
cmnd-}= next tabcmnd-{= previous tab
Windows
ctrl-w n= create new window above current windowctrl-w s= split window horizontally in twoctrl-w v= split window vertically in twoctrl-w w= switch between open windowsctrl-w j= switch to window below current windowctrl-w k= switch to window above current windowctrl-w t= switch to top windowctrl-w b= switch to bottom windowctrl-w q= close current windowctrl-w o= close all windows except current onectrl-w _= maximize current windowctrl-w == split windows equallyctrl-w -= shrink current window by one linectrl-w += grow current window by onelinectrl-w <number> -= shrink curent window by number linesctrl-w <number> += grow curent window by number linesctrl-w K= move current window to topctrl-w J= move current window to bottom
File Navigation
:n .<enter>= show current directory listing. presss enter to open selected file
System
:help runtimepath= open help window for vim’s runtime info
Working Directory
:cd <directory>= change the global vim working directory:lcd <directory>= change the working directory for the current window