Vim Commands Cheat Sheet



Vim Commands Cheat Sheet Marking Moving Moving by Screens Inserting Editing Undoing/Redoing Deleting Visual Commands Marks and Jumps Multiple Files. # /pattern?pattern n N Macros Color Schemes Searching Copying Cutting Pasting h j k l #h j/k/l b / B w / W e / E 0 (zero) $ ^ #G / #gg /:# move cursor left move cursor down move cursor up move cursor right. This cheat sheet is intended to be a quick reminder for the main concepts involved in using the command line program Vim (or vi) and assumes you already understand its usage. It does not cover every command in Vim, only the ones we consider to be useful for most people for. Vim Commands Cheat Sheet. Invoking Vim Exiting Vim Switching Modes Editing a File Moving Around Inserting Text Inserting a File Word Completion Deleting Text Changing (or Replacing) Text Copying (Yanking) and Moving Text: Undo/Redo/Repeat Searching Substituting (Searching and Replacing) Selecting Text (Visual Mode) Marks. Vim cheat sheet Allison McKnight (aemcknig@andrew.cmu.edu) Navigation h Move left H Top line on screen j Move down M Middle line on screen k Move up L Bottom line on screen l Move right 10j Move down 10 lines gg First line of the le e The end of the current word G Last line of the le b Beginning of current.

  1. Printable Vim Cheat Sheet Pdf
  2. Vim Commands Cheat Sheet Printable
  3. Vim Ctrl Command
  4. Vim Commands Cheat Sheet Pdf
  5. Vim Commands Cheat Sheet Pdf
  6. Vim Visual Mode Cheat Sheet

J - move cursor down. K - move cursor up. L - move cursor right. H - move to top of screen. M - move to middle of screen. L - move to bottom of screen. W - jump forwards to the start of a word. W - jump forwards to the start of a word (words can contain punctuation) e - jump forwards to the end of a word.

A useful collection of Vim cheat sheets to help you learn Vim editor faster. You can use them and download them for free.

Vim is an excellent terminal based text editor. The one problem with Vim is that it doesn’t function the same way as the regular graphical editors. You must know basic Vim commands in order to start using it. If you want to use it more effectively, you need to master the keyboard shortcuts.

If you want to master Vim and its shortcuts, you need to use it extensively. A cheat sheet comes handy in such a case. You can print it and keep it on your desk and when you seem at loss, just look at it for a quick reference.

Now the question is: Where can you find such Vim shortcut cheat sheet? Fret not, I have collected some of them here that you can download and use it.

Best Vim cheat sheet you can download for free

For your convenience, I have categorized them. So you get Vim command in PDF format, online Vim cheat sheet, cheat sheet for beginners and advanced users etc.

Before you see all that, let me share a simple Vim cheat sheet I created that displays only the absolute essential Vim commands. You can download it for free from the link below.

Essential Vim Commands Cheat Sheet

A simple Vim cheat sheet I created that displays only the absolute essential Vim commands.

Download Vim cheat sheets in PDF format

Here are some cheat sheets that you can download in PDF format. You can use them on your computer or print them and pin them on your desk.

Vim Cheat Sheet for Beginners

All the essential Vim commands can be found in this two-page cheat sheet.

Download here.

Vim Cheat Sheet for Programmers

Aimed at coders, it provides a number of shortcuts at a glance.

Download here.

Printable Vim Cheat Sheet Pdf

Vim Graphical Cheat Sheet (for advanced users)

A comprehensive, multiple pages cheat sheet for advanced users.

Download here.

Online Vim cheat sheets

Here are some websites that list helpful Vim commands. You can bookmark them for quick access. This also saves environment as you don’t need to print them.

Vim Cheat Sheet Wallpaper

You can get this Vim wallpaper in various colors and formats from its GitHub repository.

The key is to rely on one or two cheat sheets at max. Referring to too many Vim cheat sheets may become counterproductive.

Want to learn Vim seriously? Try this

If you are serious about learning Vim, you may purchase this ebook and video combination from Jovica Ilic, an expert Vim user.

Which is your favorite Vim cheat sheet? Did I list it here? Do share your views in the comment section.

Become a Member for FREE
Become a member to get the regular Linux newsletter (2-4 times a month) and access member-only contents.

Join the conversation.

How to Exit

:q[uit]Quit Vim. This fails when changes have been made.
:q[uit]!Quit without writing.
:cq[uit]Quit always, without writing.
:wqWrite the current file and exit.
:wq!Write the current file and exit always.
:wq {file}Write to {file}. Exit if not editing the last
:wq! {file}Write to {file} and exit always.
:[range]wq[!][file] Same as above, but only write the lines in [range].
ZZWrite current file, if modified, and exit.
ZQQuit current file and exit (same as ':q!').
Commands

Editing a File

:e[dit]Edit the current file. This is useful to re-edit the current file, when it has been changed outside of Vim.
:e[dit]!Edit the current file always. Discard any changes to the current buffer. This is useful if you want to start all over again.
:e[dit] {file}Edit {file}.
:e[dit]! {file}Edit {file} always. Discard any changes to the current buffer.
gfEdit the file whose name is under or after the cursor. Mnemonic: 'goto file'.

Inserting Text

aAppend text after the cursor [count] times.
AAppend text at the end of the line [count] times.
iInsert text before the cursor [count] times.
IInsert text before the first non-blank in the line [count] times.
gIInsert text in column 1 [count] times.
oBegin a new line below the cursor and insert text, repeat [count] times.
OBegin a new line above the cursor and insert text, repeat [count] times.

Inserting a file

:r[ead] [name]Insert the file [name] below the cursor.
:r[ead] !{cmd}Execute {cmd} and insert its standard output below the cursor.

Deleting Text

<Del> or
x
Delete [count] characters under and after the cursor
XDelete [count] characters before the cursor
d{motion}Delete text that {motion} moves over
ddDelete [count] lines
DDelete the characters under the cursor until the end of the line
{Visual}x or
{Visual}d
Delete the highlighted text (for {Visual} see Selecting Text).
{Visual}CTRL-H or
{Visual}
When in Select mode: Delete the highlighted text
{Visual}X or
{Visual}D
Delete the highlighted lines
:[range]d[elete]Delete [range] lines (default: current line)
:[range]d[elete] {count}Delete {count} lines, starting with [range]
Sheet

Changing (or Replacing) Text

r{char}replace the character under the cursor with {char}.
REnter Insert mode, replacing characters rather than inserting
~Switch case of the character under the cursor and move the cursor to the right. If a [count] is given, do that many characters.
~{motion}switch case of {motion} text.
{Visual}~Switch case of highlighted text

Substituting

:[range]s[ubstitute]/{pattern}/{string}/[c][e][g][p][r][i][I] [count]For each line in [range] replace a match of {pattern} with {string}.
:[range]s[ubstitute] [c][e][g][r][i][I] [count] :[range]&[c][e][g][r][i][I] [count]Repeat last :substitute with same search pattern and substitute string, but without the same flags. You may add extra flags
Vim Commands Cheat Sheet

Copying and Moving Text

'{a-zA-Z0-9.%#:-'}Use register {a-zA-Z0-9.%#:-'} for next delete, yank or put (use uppercase character to append with delete and yank) ({.%#:} only work with put).
:reg[isters]Display the contents of all numbered and named registers.
:reg[isters] {arg}Display the contents of the numbered and named registers that are mentioned in {arg}.
:di[splay] [arg]Same as :registers.
['x]y{motion}Yank {motion} text [into register x].
['x]yyYank [count] lines [into register x]
['x]Yyank [count] lines [into register x] (synonym for yy).
{Visual}['x]yYank the highlighted text [into register x] (for {Visual} see Selecting Text).
{Visual}['x]YYank the highlighted lines [into register x]
:[range]y[ank] [x]Yank [range] lines [into register x].
:[range]y[ank] [x] {count}Yank {count} lines, starting with last line number in [range] (default: current line), [into register x].
['x]pPut the text [from register x] after the cursor [count] times.
['x]PPut the text [from register x] before the cursor [count] times.
['x]gpJust like 'p', but leave the cursor just after the new text.
['x]gPJust like 'P', but leave the cursor just after the new text.
:[line]pu[t] [x]Put the text [from register x] after [line] (default current line).
:[line]pu[t]! [x]Put the text [from register x] before [line] (default current line).

Undo/Redo/Repeat

uUndo [count] changes.
:u[ndo]Undo one change.
CTRL-RRedo [count] changes which were undone.
:red[o]Redo one change which was undone.
UUndo all latest changes on one line. {Vi: while not moved off of it}
.Repeat last change, with count replaced with [count].

Moving Around

h or
[count] characters to the left (exclusive).
l or
or
[count] characters to the right (exclusive).
k or
or
CTRL-P
[count] lines upward
j or
or
CTRL-J or
or
CTRL-N
[count] lines downward (linewise).
0To the first character of the line (exclusive).
<Home>To the first character of the line (exclusive).
^To the first non-blank character of the line
$ or
<End>
To the end of the line and [count - 1] lines downward
g0 or
g<Home>
When lines wrap ('wrap on): To the first character of the screen line (exclusive). Differs from '0' when a line is wider than the screen. When lines don't wrap ('wrap' off): To the leftmost character of the current line that is on the screen. Differs from '0' when the first character of the line is not on the screen.
g^When lines wrap ('wrap' on): To the first non-blank character of the screen line (exclusive). Differs from '^' when a line is wider than the screen. When lines don't wrap ('wrap' off): To the leftmost non-blank character of the current line that is on the screen. Differs from '^' when the first non-blank character of the line is not on the screen.
g$ or
g<End&gr;
When lines wrap ('wrap' on): To the last character of the screen line and [count - 1] screen lines downward (inclusive). Differs from '$' when a line is wider than the screen. When lines don't wrap ('wrap' off): To the rightmost character of the current line that is visible on the screen. Differs from '$' when the last character of the line is not on the screen or when a count is used.
f{char}To [count]'th occurrence of {char} to the right. The cursor is placed on {char} (inclusive).
F{char}To the [count]'th occurrence of {char} to the left. The cursor is placed on {char} (inclusive).
t{char}Till before [count]'th occurrence of {char} to the right. The cursor is placed on the character left of {char} (inclusive).
T{char}Till after [count]'th occurrence of {char} to the left. The cursor is placed on the character right of {char} (inclusive).
;Repeat latest f, t, F or T [count] times.
,Repeat latest f, t, F or T in opposite direction [count] times.
- <minus>[count] lines upward, on the first non-blank character (linewise).
+ or
CTRL-M or
<CR>
[count] lines downward, on the first non-blank character (linewise).
_ <underscore>[count] - 1 lines downward, on the first non-blank character (linewise).
<C-End> or
G
Goto line [count], default last line, on the first non-blank character.
<C-Home> or
gg
Goto line [count], default first line, on the first non-blank character.
<S-Right> or
w
[count] words forward
<C-Right> or
W
[count] WORDS forward
eForward to the end of word [count]
EForward to the end of WORD [count]
<S-Left> or
b
[count] words backward
<C-Left> or
B
[count] WORDS backward
geBackward to the end of word [count]
gEBackward to the end of WORD [count]
These commands move over words or WORDS.

A word consists of a sequence of letters, digits and underscores, or asequence of other non-blank characters, separated with white space (spaces,tabs, ). This can be changed with the 'iskeyword' option.

A WORD consists of a sequence of non-blank characters, separated with whitespace. An empty line is also considered to be a word and a WORD.

([count] sentences backward
)[count] sentences forward
{[count] paragraphs backward
}[count] paragraphs forward
]][count] sections forward or to the next '{' in the first column. When used after an operator, then the '}' in the first column.
][[count] sections forward or to the next '}' in the first column
[[[count] sections backward or to the previous '{' in the first column
[][count] sections backward or to the previous '}' in the first column

Screen movement commands

Vim Commands Cheat Sheet Printable

z.Center the screen on the cursor
ztScroll the screen so the cursor is at the top
zbScroll the screen so the cursor is at the bottom

Marks

Vim Ctrl Command

m{a-zA-Z}Set mark {a-zA-Z} at cursor position (does not move the cursor, this is not a motion command).
m' or
m`
Set the previous context mark. This can be jumped to with the '' or '``' command (does not move the cursor, this is not a motion command).
:[range]ma[rk] {a-zA-Z}Set mark {a-zA-Z} at last line number in [range], column 0. Default is cursor line.
:[range]k{a-zA-Z}Same as :mark, but the space before the mark name can be omitted.
'{a-z}To the first non-blank character on the line with mark {a-z} (linewise).
'{A-Z0-9}To the first non-blank character on the line with mark {A-Z0-9} in the correct file
`{a-z}To the mark {a-z}
`{A-Z0-9}To the mark {A-Z0-9} in the correct file
:marksList all the current marks (not a motion command).
:marks {arg}List the marks that are mentioned in {arg} (not a motion command). For example:

Searching

/{pattern}[/]Search forward for the [count]'th occurrence of {pattern}
/{pattern}/{offset}Search forward for the [count]'th occurrence of {pattern} and go {offset} lines up or down.
/<CR>Search forward for the [count]'th latest used pattern
//{offset}<CR>Search forward for the [count]'th latest used pattern with new. If {offset} is empty no offset is used.
?{pattern}[?]<CR>Search backward for the [count]'th previous occurrence of {pattern}
?{pattern}?{offset}<CR>Search backward for the [count]'th previous occurrence of {pattern} and go {offset} lines up or down
?<CR>Search backward for the [count]'th latest used pattern
??{offset}<CR>Search backward for the [count]'th latest used pattern with new {offset}. If {offset} is empty no offset is used.
nRepeat the latest '/' or '?' [count] times.
NRepeat the latest '/' or '?' [count] times in opposite direction.

Vim Commands Cheat Sheet Pdf

Selecting Text (Visual Mode)

To select text, enter visual mode with one of the commands below, and usemotion commands to highlight the text you are interestedin. Then, use some command on the text.

vstart Visual mode per character.
Vstart Visual mode linewise.
<Esc>exit Visual mode without making any changes

How to Suspend

Vim Commands Cheat Sheet Pdf

CTRL-ZSuspend Vim, like ':stop'. Works in Normal and in Visual mode. In Insert and Command-line mode, the CTRL-Z is inserted as a normal character.
:sus[pend][!] or
:st[op][!]
Suspend Vim. If the '!' is not given and 'autowrite' is set, every buffer with changes and a file name is written out. If the '!' is given or 'autowrite' is not set, changed buffers are not written, don't forget to bring Vim back to the foreground later!

Vim Visual Mode Cheat Sheet

Daniel Gryniewicz / dang@fprintf.net