Mode Switching
| Key | Action |
|---|---|
i | Insert before cursor |
a | Insert after cursor |
o | Open a new line below |
O | Open a new line above |
Esc | Return to Normal mode |
v | Visual mode |
V | Visual Line mode |
Ctrl+v | Visual Block mode |
: | Command-line mode |
Cursor Movement (Normal mode)
CODE
h j k l ← ↓ ↑ →
w / b next/previous word start
e end of word
0 / $ start/end of line
gg / G start/end of file
50G go to line 50
Ctrl+f / b page down/up
% jump to matching bracketEditing Commands
CODE
dd delete current line (cut)
5dd delete 5 lines
yy yank (copy) current line
5yy yank 5 lines
p / P paste (below/above)
u undo
Ctrl+r redo
x delete character under cursor
dw delete word
cw change word (delete then insert mode)
. repeat last commandSearch and Replace
VIM
/pattern search downward
?pattern search upward
n / N next/previous match
* search word under cursor
" replace all
:%s/old/new/g
" replace with confirmation
:%s/old/new/gc
" specific range (lines 10–20)
:10,20s/old/new/g
" ignore case
:%s/old/new/giVisual Block (Ctrl+v)
Useful when you need to edit multiple lines at once.
- Enter Visual Block mode with
Ctrl+v - Select the range with
j/k I→ type text →Esc: insert at the start of each lined: delete the block>/<: indent / unindent
Recording Macros
CODE
qa start recording into register 'a'
... perform edits
q stop recording
@a play the macro
10@a play 10 times
@@ replay last macroMulti-file Editing
VIM
:e file.txt open a file
:sp file.txt horizontal split
:vsp file.txt vertical split
Ctrl+w w switch split windows
Ctrl+w = equalize window sizes
:tabnew file.txt open in a new tab
gt / gT next/previous tab
:tabn 2 go to tab 2
:buffers list open buffers
:b2 switch to buffer 2Useful Settings (~/.vimrc)
VIM
set number " line numbers
set relativenumber " relative line numbers
set tabstop=2 " tab width
set expandtab " use spaces for tabs
set autoindent
set hlsearch " highlight search
set incsearch " incremental search
set ignorecase
set smartcase
syntax on
colorscheme desertEditorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)Linux man pages ↗
Questions & answers
Ask a question about this guide. We'll review and reply.