VI editor
A comprehensive guide to using the VI/Vim text editor in Linux, from basic operations to advanced features.
π Getting Started
Opening and Closing
# Starting VI
vi filename # Open file in VI
vim filename # Open file in VIM
view filename # Open in read-only mode
vimdiff file1 file2 # Compare files
# Saving and Quitting
:w # Save changes
:q # Quit (if no changes)
:wq or :x # Save and quit
:q! # Quit without saving
ZZ # Save and quitπ Basic Navigation
Moving the Cursor
h # Move left
j # Move down
k # Move up
l # Move right
0 # Start of line
$ # End of line
w # Next word
b # Previous word
gg # Start of file
G # End of fileScreen Navigation
ctrl+f # Page forward
ctrl+b # Page backward
ctrl+d # Half page forward
ctrl+u # Half page backward
H # Move to top of screen
M # Move to middle of screen
L # Move to bottom of screenβοΈ Basic Editing
Inserting Text
i # Insert before cursor
I # Insert at start of line
a # Append after cursor
A # Append at end of line
o # Open line below
O # Open line aboveDeleting Text
x # Delete character
dd # Delete line
dw # Delete word
d$ # Delete to end of line
d0 # Delete to start of line
D # Delete to end of lineCopying and Pasting
yy # Copy line
yw # Copy word
y$ # Copy to end of line
p # Paste after cursor
P # Paste before cursorπ Undo and Redo
History Operations
u # Undo last change
ctrl+r # Redo last change
U # Undo changes on line
. # Repeat last commandπ Search and Replace
Search Operations
/pattern # Search forward
?pattern # Search backward
n # Next occurrence
N # Previous occurrence
* # Search word under cursor
# # Search word under cursor backwardReplace Operations
:s/old/new # Replace first occurrence in line
:s/old/new/g # Replace all occurrences in line
:%s/old/new/g # Replace all occurrences in file
:%s/old/new/gc # Replace with confirmationπ Visual Mode
Visual Selection
v # Character visual mode
V # Line visual mode
ctrl+v # Block visual mode
gv # Reselect last selectionVisual Operations
> # Indent selection
< # Unindent selection
y # Copy selection
d # Delete selection
~ # Change caseπ― Advanced Navigation
Word Navigation
e # End of word
ge # End of previous word
W # Next WORD
B # Previous WORD
E # End of WORDLine Navigation
:n # Go to line n
nG # Go to line n
ngg # Go to line n
% # Matching parenthesis
{ # Previous paragraph
} # Next paragraphπ οΈ Advanced Editing
Change Operations
cw # Change word
cc # Change line
c$ # Change to end of line
ci" # Change inside quotes
ca" # Change around quotes
ct<char> # Change until characterText Objects
iw # Inner word
aw # A word
is # Inner sentence
as # A sentence
ip # Inner paragraph
ap # A paragraphπ Multiple Files
Buffer Operations
:ls # List buffers
:bn # Next buffer
:bp # Previous buffer
:bd # Delete buffer
:b name # Switch to bufferWindow Operations
:sp filename # Split horizontal
:vsp filename # Split vertical
ctrl+w h/j/k/l # Navigate windows
ctrl+w +/- # Resize window
ctrl+w = # Equal size windowsπ¨ Customization
Settings
:set number # Show line numbers
:set nonumber # Hide line numbers
:set paste # Paste mode
:set nopaste # Normal mode
:set syntax=on # Enable syntax highlightingConfiguration
~/.vimrc # User configuration file
:colorscheme name # Change color scheme
:set tabstop=4 # Set tab width
:set expandtab # Use spaces for tabsπ Macros
Recording
q<letter> # Start recording to register
q # Stop recording
@<letter> # Play macro
@@ # Repeat last macroπ‘ Best Practices
Navigation
Use motions over arrow keys
Learn text objects
Master search operations
Use marks for quick navigation
Editing
Use registers effectively
Learn compound commands
Use macros for repetitive tasks
Master visual mode
Configuration
Customize your .vimrc
Use plugins wisely
Create useful mappings
Document your settings
π§ Advanced Features
Marks
m<letter> # Set mark
'<letter> # Go to mark line
`<letter> # Go to mark position
:marks # List all marksRegisters
"<letter>y # Yank to register
"<letter>p # Paste from register
:reg # List registers
"+ or "* # System clipboardTags
:tag function # Jump to function
ctrl+] # Jump to definition
ctrl+t # Jump back
:tags # Show tag stackπ Learning Path
Beginner Level
Basic navigation (hjkl)
Basic editing (i, a, d, y, p)
Save and quit commands
Simple searches
Intermediate Level
Text objects
Visual mode
Multiple windows
Basic macros
Advanced Level
Complex text objects
Advanced macros
Registers
Custom mappings
π Productivity Tips
Speed Optimization
Use relative numbers
Master text objects
Use marks
Create mappings
Common Workflows
Multiple file editing
Search and replace
Code navigation
Block operations
Plugin Management
Essential plugins
Plugin managers
Custom configurations
Performance tuning
Last updated
Was this helpful?