Vim Cheat Sheet
Global
:ter[minal] Open a terminal windowu UndoCtrl + r Redo
Quitting
:x or :wq Exit, saving changes:w Writing to a file, not quiting:q Exit, if there is no changesZZ Exit and save changes if any:q! Exit without saving any changes
Inserting
i Inserting before cursorI Inserting before linea Append after cursorA Append after lineo Open a new line after current lineO Open a new line before current liner Replace single characterR Replace many character
Deleting
x Delete character at the cursorX Delete character before the cursorD Delete from cursor to the end of the linedd or :d Delete current line
Changing Text
guu Lowercase linegUU Uppercase line~ Toggle uppercase and lowercase
Ranges
:n,m Range - line n to m:. Range - current line:$ Range - last line:% Range all lines:g/{pattern} Range all files that mathces pattern:g!/{pattern} Range all files that doesn't mathces pattern
Visual Mode
v Start the visual mode, then we can do a command like yankV Start a linewise visual modeCtrl + v Start visual block modeo Move to other end of marked area (top to bottom)O Move to the corner of the block (right)aw Mark a wordab or a( Block with ()aB or a{ Block with {}at Block with <>ib or i( Inner block with ()iB or i{ Inner block with {}it Inner block with <>y Yank(copy) marked textd Delete marked text~ Toggle case for marked text> Shift text right / Tab< Shift text left / Shift+Tab= Autoindent marked textEsc Exit visual mode
Indent text
>> Move right<< Move left>% Indent block with cursor {} ()<% Deindent block with cursor {} () ]p Paste and indent block=% Reindent block with cursor {} ()
Cut and Paste
yy or Y Yank(copy) a linep Paste after cursorP Paste before cursordd Delete a lineD Delete to the end of the linex Cut character:1,6d Delete lines 1 to 6:.,$d From current line to end:g/{pattern}/d Delete lines with pattern:g!/{pattern}/d Delete lines without pattern
Searching
/{pattern} Search forward for the pattern string?{pattern} Search backward for the pattern stringn Next instance of the stringN Previous instance of the string
Replacing
:s/{pattern}/{replace}/flags Replace all occurence of 'pattern' with 'replace' on a single line :%s/article/tutorial/flags Replace all occurence 'pattern' with 'replace' on a every line of file g Flag - Replace all occurencec Flag - Confirm replaces
Working with multiple files
:NERDTree File system explorer for the Vim editor (need to install manually, see vim customization blog):FZF Search among the files in the project (need to install manually, see vim customization blog)Ctrl + ww To switch between windowsCtrl + wh To go to left windowsCtrl + wl To go to right windows:bn[ext] Go to next buffer:bp[revious] Go to previous buffer:bd[elete] Delete buffer / Close files:b# Go to buffer by index:ls List all open buffers:sp[lit] {filename} Open the file in horizontal split:vs[plit] {filename} Open the file in vertical split:tab ba Edit all buffers as vertical gt Go to next buffer{n}gt Go to n index bufferCtrl + ws Split windowsCtrl + wq Quit window
