VI Cheat Sheet

VI Cheat Sheet

opening multiple files

$ vim file1 file2
:e filename

switching between files

:n || :bn - switch to the next file
:N || :bp - switch to the previous file

:bf - switch to the first file
:bl - switch to the last file

:b <number> - switch to a specific file number
:b <filename> - switch to a specific file filename

:e# || Ctrl+^ - witch back and forth between two files

:ls - list all open files (In the ls: output, the % refers to the current file, while the # refers to the alternate file)

:wall - save (write) all open files
:bw - quit the current file
:qall - quit all open files
:qall! - forcefully quit all files, discsarding changes

opening and switching between multiple windows

splitting windows horizontally

$ vim -o file1 file2
:split <filename> || Ctrl+w,s - split windows horizontally in Vim; if no file filename is given the current file will be displayed in both splits

splitting windows vertically

$ vim -O file1 file2
:vsplit <filename> || Ctrl+w,v - split windows vertically in Vim

Ctrl+w, j || Ctrl+w, Down arrow - switch to the next window below the current window
Ctrl+w, k || Ctrl+w, Up arrow - switch to the next window above the current window

Ctrl+w,l || Ctrl+w,Right arrow- switch to the next window to the right of the current windowCtrl+w,h|| Ctrl+w,Left arrow - switch to the next window to the left of the current window

ctrl+w,w - cycle through all Vim windows

quitting windows

:close || Ctrl+w,c- close the current window
:only || Ctrl+w,o - close all windows except the current window

Comments