Vi/vim Essential Command Reference

ADVERTISEMENT

VI/VIM Essential Command Reference
By Donald Raymond
and Mary Piper
Basic Controls & Commands
Editing and Saving Files
Esc - Basic command mode (Default mode)
:e filename - Edit a new file (add to buffer)
i - Insert mode (for inserting text)
:enew - New empty file
gg/G - Move to top/bottom of file
:read !command - Insert command output
0/$ - Move to begin/end of line
:x or ZZ - Save and quit if file was changed
w/b - Move to next/previous word
:w >> file2 - Append contents of file to file2
. - Repeat last command
dw/dd - Delete word/line
V/v - Visual mode for selecting lines/char
u - Undo
:%s/search/replace/gc - Search and replace
Ctrl + u - Redo
:f newname - Change file name to newname
:w file - Write file
i/a - Insert text before/after char
:wq - Write and quit (:wq! to enforce)
I/A - Insert text at start/end of line
:q! - Quit without saving
O/o - Insert new line above/below cursor
Navigation and Searching
r - Replace char
:n - Move cursor to line n
cw/cc - Replace word/line
Ctrl + u/d - Move down/up half page
R - Replace text (typeover)
Ctrl + f/b - Move down/up a full page
s/S - Delete char/line and insert text
e - Move to end of word
~/g~~ - Reverse case of char/line
h/j/k/l - Move cursor left/down/up/right
H/M/L - Jump to top/middle/bottom of page
Deleting and Copying Text
:n - Move cursor to line n
x/X - Delete current/previous char
fn - Search forward for next n
nd - Delete line #n
/pattern ?pattern - Search pattern forward/back
D or d$ - Delete rest of line
n/N - Next/previous occurrence of search pattern
d0 - Delete from here to beginning of line
# - Search for word under cursor
Y or yy - Copy to register
:help topic - Show documentation for topic
y0/y$ - Copy to beginning/end of line
p/P - Paste register after/before cursor
Buffers & Windows
:ls or :files - Display list of opened files
Other Useful Commands
:b n - Open file n in current window
view file - Open file in read-only mode
:bdn - Delete file #n from buffer
:sh - open shell (exit to re-enter vi)
:next/previous - Move to next/previous file
: !command - Run system command in VI
:first/last - Switch to first/last file
:e . - Browse a directory and display file explorer
:e! - Reload current file
:command - Execute command in vi
Ctrl + wn or :new - New empty window
:cd path/to/dir - Change directory
Ctrl + ws or :sp - Split window horizontally
:noh - Disable search highlighting
Ctrl + wv or :vsp - Split window vertically
:Sex - Split window and show file explorer (Hor)
Ctrl + wc or :close - Close window
:Sex! - Split window and show file explorer (Ver)
Ctrl + wo or :only - Close all but current window
vimdiff file1 file2 - Compare two files
Ctrl + ww - Jump to next window
n| - Move cursor to column n
Ctrl + w[hjkl] - Move window focus
* - Go to next occurrence of word under cursor
Ctrl + w[HJKL] - Move window
nG - Go to line n
:resize/vertical resize +n - Resize window (Hor/ver)

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go