Basic
ESC
enter command modei
enter insert mode at the current cursor positiona
enter insert mode after the current cursor positiono
new line below current cursor position:wq
write and quitq!
quit without saving:w
write:w file
write asfile
dd
delete lineyy
yank the linep
paste below current cursor positionP
paste above current cursor positionv
enter visual modeu
undoCtrl+r
redogg
go to first lineG
go to last line/text
search forward?test
search backwards^
go to beggining of line$
go to end of line!ls
add the output ofls
:r !ls
add the output ofls
:%s/old/new/g
substitute all occurrences ofold
withnew
:7
go to line7
Files
gf
open the filename of the cursor selectionctrl+6
to go back and forthctrl+o
to go backctrl+w gf
to open a new tabgt
next tabgT
previous tab
Buffers
:bn
buffer next or:bp
buffer previous.:b1
or:b2
also worksCTRL+^
go to the last edited file in the same window:n
:N
go 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