Modes and Basic movement
vim - shows info about vimdefault mode is command modej/k/h/l - navigationi - insert modeesc - go back to command mode
Faster Movement
w - jump from word to wordW - move whole wordb - go back to wordB - back to whole wordA - append at the end of line $ - go to end of line^ - go to first non space char of line0 - go to very beginning of linegg - begining of fileG - go to end of file} - jump to next paragraph{ - back to paragraphf* - will find the first occurance of * in the lineF* - find backwords the * chart* - till the occurence of *T* - backward occurence of *8gg - 8th line8G - 8th line:8 - go to 8th line; - repeat the last search, - repeat last search on opposite direction
Basic Editing
:e ~/.vimrcx - delete current characteru - undo the previous changedw - delete the worddb - delete the previous word5dw - delete 5 wordscw - change the worddd - delete the current linecc - change the whole linedt" - delete inside quotesct" - change the string inside the ""ci" - change inside "/{/[/' and so onca" - change around "
Cut, Copy and Paste
dw - delete the wordp - paste from bufferP - paste from buffer starting from one column behinddj - delete current and immediate follwing lineyw - copy the current wordyy - copy the current liney0 - copy everything before the cursor to beginning of the linedh - delete previous character dl - delete current chardj - delete current line and next linedk - delete current line and above linex - delete char under the cursor
Searching
/text - search for text {case sensitive}n - go to next search resultN - back back to previous search result?text - search for text backwards:set incsearch - set incremental search:set ignorecase - case insensitive search:set hlsearch - highlight search:nohlsearch - disable highligh search:noh - a shortcut for :nohlsearchd/chalam - delete all the text from the postion of cursor to textit works the same with change and yank./.[gain] - finds *gain/\n\n - finds all empty lines in the file
Replace
:s/find/replace - substitute a word for another:%s/find/replace - repeat the above for entire file:%/find/replace/g - substitute globally ( all occurances in the file )v - visual modeshit + v - visual line modeshift + % - finding matched brace:%/find/replace/gc - substitute after conformationgv - select previous visually:s/find/replace/gci - case insensitive replacement/[^ ](/[^ ]\zs(/),/)\ze,
Macros and registers
:registersqa - to record a macro@a -execute a macroctrl + g - inforamtion about current file
Advanced Movements
ctrl + d - move half wat down in the current screencrtl + u - move half up in current screenctctrl + f - full screen downcrtl + b - full screen upM - go to middleL - last line of windowH - go to top3L - 3rd line from the last3H - 3rd from the topzt - current line stays on the top of pagezb - bottomzz - middle of the windowMarkersm followed by register to mark' followed by register to go to mark'' - go to visited places
Invoking the command line directly from vim
:! - can use commands:read !command - brings command result into the file:r !curl --silent url - brings url to file:se ft=javascript
Buffers
:bn - navigate to the next buffer:bp - previous buffer in the list:b# - navigate to previous buffer:bf - first bufferO - inset new line before@@ - recent macro again:bd - delete current buffer:bd12 - delete 12 buffer
Windows and tabs
:e url - edit a file:vsplit url - vertical split the screenctrl + w + hjkl - switch between files in a screenctrl + w + +/- to resize the windowctrl + w + e - resize all windows equally:sb2 - new split window in top:vert sb3 - :tabedit url -:tabe url - open a new tabgt - go to next tabgT - go to previous tab:gf - go to first tab
Indents and folds
>> - indentation of tab:set list - :set expandtab:set noexpandtab:set shiftwidth = 4<< - undo indent2>> - indent 2 lines:set nolist'o' - other side of visual selectiongv - reselect the previous selecto - go to new after the cursor:set smartindent= - auto indentation=3j - auto indent 3 lines next to current postion:set softtabstop = 4ctrl + t - indent in insert mod3ectrl + d - undo indentzf5j - fold the next five lineszo - open foldzc - closezd - deletezi - invert foldings:set foldmenthod = s:yntax:se fdm = syntaxzC - close fold from current to topzO - to every single folding inside:se fmd = marker :set foldmarker = {{{,}}}
Vimrc file
set nocompatiblefiletype onfiletype indent onfiletype plugin onset backspace=indent,eol,startset smartcaseset gdefaultset incsearchset showmatchset list:so %set noswapfileset visualbellset cursorline
Others
:newtab - open a new tab