Cheatsheet for Buffers, Windows and Tabs of Vim
My cheatsheet to operate the bufers, windows and tabs of Vim.
Buffers
:badd: buffer add:ls: list buffer
buffer indicators:%: buffer in current windowa: active buffer#: alternate buffer, which can be accessed byCtrl-6: no indicator means that buffer is not loaded yet
:bp: load previous buffer into current window:bn: load next buffer into current window:b2: load buffer No. 2 into current window:br: rewind first buffer into current window:bl: load last buffer into current window:ba: open all buffers into different windows:bd: delete buffer, take buffer number as arguments,:bd 1 2 3
Windows
vim -o file1.txt file2.txt: open files in two horizotally split windowvim -O file1.txt file2.txt: open files in two vertically split window:sp file.txt: open file as horizontal split:vs file.txt: open file as vertical split:n file.txt: new a file in current windowCtrl-w n: new a file in horizontal split,:w file.txtfor saving:vne file.txt: new a file in vertical split-
Ctrl-w h/j/k/l: switch window Ctrl-w H/J/K/L: move windowCtrl-w T: move current window to a new tabCtrl-w r: rotates the windows from left to right or from top to bottom-
Ctrl-w R: rotates the windows from the other direction Ctrl-w =: resize the windows equallyCtrl-w >: incrementally increase the window to the right, takes a parameter, e.g.Ctrl-w 20 >Ctrl-w <: incrementally increase the window to the leftCtrl-w -: incrementally decrease the window’s heightCtrl-w +: incrementally increase the window’s heightCtrl-w _: maximize the window’s height
Tabs
vim -p file1.txt file2.txt: open files in separate tabs:tabnew file.txt: open file.txt in a new tab:tabc: close current tab:tabn: go to next tab:tabn 2: go to tab No. 2:tabp: go to previous tab:tabr: rewind to first tab:tabl: go to last tab