Basic
ESCenter command modeienter insert mode at the current cursor positionaenter insert mode after the current cursor positiononew line below current cursor position:wqwrite and quitq!quit without saving:wwrite:w filewrite asfiledddelete lineyyyank the lineppaste below current cursor positionPpaste above current cursor positionventer visual modeuundoCtrl+rredogggo to first lineGgo to last line/textsearch forward?testsearch backwards^go to beggining of line$go to end of line!lsadd the output ofls:r !lsadd the output ofls:%s/old/new/gsubstitute all occurrences ofoldwithnew:7go to line7
Files
gfopen the filename of the cursor selectionctrl+6to go back and forthctrl+oto go backctrl+w gfto open a new tabgtnext tabgTprevious tab
Buffers
:bnbuffer next or:bpbuffer previous.:b1or:b2also worksCTRL+^go to the last edited file in the same window:n:Ngo to the next or previous arg file.
If you want to jump to a file as you wish:
- :b partial_word then press Tab, you will get auto completion. or :b filename.
- :ls then :b number to go to that buffer.
Splits
- Split ( :sp , :split , :vs , :vsplit , 'CTRL-W s' , 'CTRL-W v' )
- Navigate ( CTRL-W {h,j,k,l} , CTRL-{h,j,k,l} )
- Move ( CTRL-W {H,J,K,L} )
- Focus ( :o , :only ,
o ) - Close ( :q , :quit ,
q )
Tabs
- Create ( CTRL-W T , :tabe )
- Move ( gt , gT , :tabn , :tabp , CTRL-PgUp , CTRL-PgDn )
- Close ( :tabclose , CTRL-t)
NERD Tree (it opens in a split)
https://www.cheatography.com/stepk/cheat-sheets/vim-nerdtree/ - Hidden files ( I ) - Open ( o , t , T , i , s ) ( open , in new tab , in new tab silently , split , vsplit ) - Preview ( go , gi , gs ) ( in current window , split , vsplit ) - Update ( r , R ) ( ? , ? )
vimdiff
Tips for vimdiff
:quitall-:qa- Quit all files:set noscrollbind- Independent scroll^w w- Move between left and right]c- jump to next change[c- jump to previous change:diffget-do- from the other side to the side you are in:diffput-dp- from where you are to the other sideu- undo:diffupdate- Re-scan the file for changeszo- Fold openzc- Fold closeza- Toggle foldzR- Open all foldszM- Close all foldszx- Update folds:only- show only the middle/merged file^o- Previously opened file:set wrap- text wrap:syn off- remove colors^w {h,j,k,l}- move:diffg RE- Get from REMOTE:diffg BA- Get from BASE:diffg LO- Get from LOCAL
Special config only for vimdiff
if &diff
set cursorline
map ] ]c
map [ [c
hi DiffAdd ctermfg=233 ctermbg=LightGreen guifg=#003300 guibg=#DDFFDD gui=none cterm=none
hi DiffChange ctermbg=white guibg=#ececec gui=none cterm=none
hi DiffText ctermfg=233 ctermbg=yellow guifg=#000033 guibg=#DDDDFF gui=none cterm=none
endif
LOCAL – this is file from the current branch BASE – common ancestor, how file looked before both changes REMOTE – file you are merging into your branch MERGED – merge result, this is what gets saved in the repo