Skip to content
Log In Sign Up info@muvcloud.com

The Modes

  • Normal mode: where Vim starts. Keys move the cursor and run commands; they do not type text.
  • Insert mode: keys type text, as in any editor. Enter it with i; leave it with Esc.
  • Visual mode: select text, then act on the selection. Enter it with v.
  • Command-line mode: type : in Normal mode, then a command such as :w, and press Enter.

When in doubt, press Esc once or twice: you are back in Normal mode. Commands are case sensitive, so u and U do different things.

Save and Quit

CommandMeaning
:wSave
:wq or :xSave and quit
ZZSave and quit
:qQuit if saved
:q!Quit, drop changes
:w new.txtWrite a copy

More, including files you may not write to, in how to save and quit in Vim.

Moving Around

KeyMoves to
h j k lLeft, down, up, right
w / bNext / previous word
0 / $Line start / end
gg / GFirst / last line
42GLine 42
Ctrl+f / Ctrl+bPage down / up
%Matching bracket

Jumping to the end of a file is covered in how to go to the end of a file in Vim.

Editing

KeyMeaning
i / aInsert before / after cursor
I / AInsert at line start / end
o / ONew line below / above
xDelete character
ddDelete line
dwDelete word
DDelete to line end
cwChange word
rReplace one character
uUndo
Ctrl+rRedo

See how to delete a line in Vim and how to undo and redo in Vim for the variations.

Copy and Paste

KeyMeaning
yyCopy line
ywCopy word
p / PPaste after / before
dd then pCut and paste a line

Vim calls copying "yanking", and every delete also stores the text, so a delete works as a cut. Details in how to copy, cut, and paste in Vim.

Search and Replace

CommandMeaning
/errorSearch forward
?errorSearch backward
n / NNext / previous match
*Next match of word
:%s/old/new/gReplace in file
:%s/old/new/gcReplace, confirm each

Patterns and ranges are explained in how to search in Vim.

Files, Buffers, and Splits

CommandMeaning
:e fileOpen a file
:lsList open buffers
:bn / :bpNext / previous buffer
:splitSplit horizontally
:vsplitSplit vertically
Ctrl+w wNext window
:qClose window

Counts and the Dot Command

Most Normal mode commands accept a number in front: 3dd deletes three lines, 5j moves five lines down, and 2yy copies two lines. The dot key . repeats your last change. Delete a word with dw, then press . to delete the next one; change a word with cw, then move to another and press . to make the same change.

Visual Mode

KeyMeaning
vSelect characters
VSelect lines
Ctrl+vSelect a block
d / yDelete / copy selection
> / <Indent / outdent

Move the cursor with the usual keys to grow the selection, then press the action key. To practice all of this, run vimtutor, a short lesson inside Vim itself. It comes with the full Vim; on Debian and Ubuntu it is part of the vim-runtime package that the vim package installs, and the small vim-tiny package does not have it.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations