Skip to content

() files (buffers), splits (windows), and layouts (tabs)

Basic

  • ESC enter command mode
  • i enter insert mode at the current cursor position
  • a enter insert mode after the current cursor position
  • o new line below current cursor position
  • :wq write and quit
  • q! quit without saving
  • :w write
  • :w file write as file
  • dd delete line
  • yy yank the line
  • p paste below current cursor position
  • P paste above current cursor position
  • v enter visual mode
  • u undo
  • Ctrl+r redo
  • gg go to first line
  • G go to last line
  • /text search forward
  • ?test search backwards
  • ^ go to beggining of line
  • $ go to end of line
  • !ls add the output of ls
  • :r !ls add the output of ls
  • :%s/old/new/g substitute all occurrences of old with new
  • :7 go to line 7

Files

  • gf open the filename of the cursor selection
  • ctrl+6 to go back and forth
  • ctrl+o to go back
  • ctrl+w gf to open a new tab
  • gt next tab
  • gT previous tab

Buffers

  • :bn buffer next or :bp buffer previous. :b1 or :b2 also works
  • CTRL+^ 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

https://devhints.io/vim-diff

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 side
  • u - undo
  • :diffupdate - Re-scan the file for changes
  • zo - Fold open
  • zc - Fold close
  • za - Toggle fold
  • zR - Open all folds
  • zM - Close all folds
  • zx - 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