Vim Cheatsheet

6 min read·Matthieu

A quick reference for Vim commands, organized for server administration work. Bookmark this page.

Modes

Mode Enter Purpose Back to Normal
Normal Esc Navigate, run commands Already there
Insert i, a, o, I, A, O Type text Esc
Visual v (char), V (line), Ctrl+v (block) Select text Esc
Command-line : Run ex commands Enter or Esc

File operations

Command Action
:w Save
:q Quit (fails with unsaved changes)
:wq or ZZ Save and quit
:q! Quit without saving
:w !sudo tee % Save a read-only file (when you forgot sudoedit)
:e /path/to/file Open file
:saveas /path Save as a new file

Character and line

Key Action
h j k l Left, down, up, right
0 Start of line
$ End of line
^ First non-blank character

Word

Key Action
w / W Next word / WORD
b / B Previous word / WORD
e End of word

File

Key Action
gg First line
G Last line
42G or :42 Line 42
Ctrl+d / Ctrl+u Half page down / up
Ctrl+f / Ctrl+b Full page down / up
% Matching bracket
Key Action
/pattern Search forward
?pattern Search backward
n / N Next / previous match
* Search word under cursor (forward)
# Search word under cursor (backward)

Entering insert mode

Key Action
i Before cursor
a After cursor
I Start of line
A End of line
o New line below
O New line above
s Delete character and insert
S or cc Delete line and insert

Editing

Command Action
x Delete character
dd Delete line
dw Delete word
d$ or D Delete to end of line
d0 Delete to start of line
cc Change line
cw Change word
ci" Change inside quotes
ci( Change inside parentheses
yy Copy line
yw Copy word
p / P Paste after / before
u Undo
Ctrl+r Redo
. Repeat last change
>> / << Indent / unindent line
J Join current line with the next

Counts and composition

Vim commands accept a count prefix. Combine operators with motions for precise edits.

Example Action
3dd Delete 3 lines
5j Move down 5 lines
d2w Delete next 2 words
4>> Indent 4 lines
y3w Copy 3 words
ct; Change text up to ;
df" Delete through next "

Visual mode

Command Action
v Start character selection
V Start line selection
Ctrl+v Start block selection
d Delete selected
y Copy selected
> / < Indent / unindent selected
:s/^/#/ Comment selected lines (in visual line mode)
U / u Uppercase / lowercase selected

Search and replace

Command Action
:s/old/new/ Replace first on current line
:s/old/new/g Replace all on current line
:%s/old/new/g Replace all in file
:%s/old/new/gc Replace all with confirmation
:5,10s/old/new/g Replace all on lines 5-10

Common regex patterns

Pattern Matches
^ / $ Start / end of line
. Any character
\d Digit
\s Whitespace
.* Any characters (greedy)
\v "Very magic" mode (less escaping)

Server examples

:%s/listen 80;/listen 443 ssl;/g
:%s/nginx:1.24/nginx:1.27/g
:%s/192\.168\.1\.1/10.0.0.1/g

Buffers

Command Action
:e file Open in buffer
:bn / :bp Next / previous buffer
:ls List buffers
:b2 Go to buffer 2
:bd Close buffer

Splits

Command Action
:sp file Horizontal split
:vs file Vertical split
Ctrl+w h/j/k/l Move between splits
Ctrl+w = Equal split sizes
Ctrl+w q Close split
Ctrl+w _ Maximize current split height
`Ctrl+w `

Tabs

Command Action
:tabnew file Open in new tab
gt / gT Next / previous tab
:tabclose Close tab

.vimrc essentials

Minimal server-tuned configuration:

set nocompatible
set encoding=utf-8
set number relativenumber
syntax on
set expandtab tabstop=2 shiftwidth=2 softtabstop=2
set incsearch hlsearch ignorecase smartcase
set showmatch laststatus=2 showmode
set mouse=a
set pastetoggle=<F2>
set noswapfile
set cursorline
set list listchars=tab:>>·,trail:·
filetype plugin indent on

Server workflow shortcuts

Task Commands
Edit root-owned file safely sudoedit /etc/nginx/nginx.conf
Paste without cascade indent F2, i, paste, F2
Jump to error line vim +42 file.yml
Convert tabs to spaces (YAML fix) :%s/\t/ /g
Comment multiple lines V, select, :s/^/#/
Uncomment multiple lines V, select, :s/^#//
Verify Nginx config after edit :!sudo nginx -t
Reload without leaving Vim :!sudo systemctl reload nginx

Troubleshooting

Problem Fix
Cannot type after opening Vim Press i (you are in Normal mode)
Terminal frozen (Ctrl+s) Press Ctrl+q
Staircase indentation on paste Toggle paste mode: F2 or :set paste
File is read-only Quit, reopen with sudoedit
Swap file warning Choose (D)elete if no other session is editing

Copyright 2026 Virtua.Cloud. All rights reserved. This content is original work by the Virtua.Cloud team. Reproduction, republication, or redistribution without written permission is prohibited.

Ready to try it yourself?

Deploy your own server in seconds. Linux, Windows, or FreeBSD.

See VPS Plans