vi filename.txt
To enable improved vim features:
echo "set nocp" >> ~/.vimrc
:q # Quit
:q! # Quit without saving
:w # Save file
:wq # Save and quit
ZZ # Save and quit (shortcut)
Press Esc
to return to command mode if uncertain.
i
, a
, o
, A
, etc.Esc
h / l # Move left / right
j / k # Move down / up
0 / $ # Start / end of line
w / b # Next / previous word
G / 1G / 5G # Go to last / first / specific line
Ctrl+F / Ctrl+B # Scroll forward / backward
i # Insert before cursor
a / A # Append after / at line end
o / O # Open new line below / above
x / 3x # Delete character(s)
dd / d$ / dW# Delete line / to end / word
u # Undo last change
dd # Cut current line
yy / yW # Copy line / word
p / P # Paste after / before
J # Join line with next
/pattern # Search forward
n # Repeat last search
:%s/old/new/g # Replace globally
:%s/term/Term/gc # Confirm each replacement
vi foo.txt bar.txt # Open multiple files
:bn / :bp # Next / previous buffer
:buffers # List open buffers
:buffer 2 # Switch to buffer 2
:r otherfile.txt # Read contents into current file
:w # Save file
:w newname.txt # Save as new file
:wq or ZZ # Save and exit
:q! # Quit without saving
The vi editor is a cornerstone of Unix and Linux text manipulation. Its modal architecture and speed offer unmatched control from the terminal. Though its interface may challenge new users, consistent practice reveals its depth for scripting, configuration, and system administration.