Skip to content

Vim Commands Cheat Sheet

  • OS: Windows 11
  • Vim: VIM - Vi IMproved 9.1
  • Neovim: NVIM v0.11.0-dev-1533+g1a8a48d7e5

Starting from Shell

  • nvim open the dash board
  • nvim . open the cwd

Exiting

CommandDescription
:wWrite (save) file without exiting
:waWrite (save) all open files without exiting
:qQuit but fail if unsaved changes exist
:qaQuit All but fail if unsaved changes exist
:q! / ZQQuit and discard unsaved changes
:wq / :xWrite (save) and quit
ZZWrite (save) and quit
:wqaWrite (save) and quit on all open files

Changing Vim Modes

CommandDescription
iEnter INSERT mode
aEnter INSERT mode after the cursor (think: append)
AEnter INSERT mode at the end of the line (think: Append)
oOpen new line below the cursor and enter INSERT mode
OOpen new line above the cursor and enter INSERT mode
vEnter character-wise VISUAL mode
VEnter line-wise VISUAL mode
<C-q>Enter block-wise VISUAL mode (Windows)
<C-v>Enter block-wise VISUAL mode (MacOS)
:Enter COMMAND-LINE mode
REnter REPLACE mode
ESCGo back to NORMAL mode from other modes
uUndo changes
<C-r>Redo changes

::: Tip Note

In Windows, the command for entering block-wise VISUAL mode is <C-q>, instead of <C-v> as in Linux/MacOS.

:::

Moving Around Within Vim

Basic Movements

CommandDescription
hMove cursor left
jMove cursor down
kMove cursor up
lMove cursor right

Same-Line Navigation

CommandDescription
0 and $Move cursor to the beginning/end of the line
^ and g_Move cursor to the first/last non-blank character in line
fx and FxFind next/previous occurrence of character ‘x’
tx and TxGo towards next/previous occurrence of character ‘x’
; and ,Repeat previous f, F, t, or T movement forwards / backwards

Word Movements

CommandDescription
wMove cursor forwards to start of word
WMove cursor forwards to start of WORD
bMove cursor backwards to start of word
BMove cursor backwards to start of WORD
eMove cursor forwards to end of word
EMove cursor forwards to end of WORD
geMove cursor backwards to end of word
gEMove cursor backwards to end of WORD

Sentence Movements

CommandDescription
)Move cursor to next sentence
(Move cursor to previous sentence

Paragraph Movements

CommandDescription
}Move cursor to next paragraph
{Move cursor to previous paragraph

Moving To Specific Lines

CommandDescription
ggMove cursor to first line of document
GMove cursor to last line of document
{number}GMove cursor to line {number}
{number}jGo {number} lines down
{number}kGo {number} lines up
{number}%Go to {number}% of the file
HMove cursor to line at the top of the window
MMove cursor to the line at the middle of the window
LMove cursor to the line at the bottom of the window
CommandDescription
<C-f>Move cursor forwards (down) one full screen
<C-b>Move cursor backwards (up) one full screen
<C-d>Move cursor down half a screen
<C-u>Move cursor up half a screen

Scrolling While Leaving Cursor In Place

CommandDescription
zzPlace current cursor line in the middle of the window
ztPlace current cursor line at the top of the window
zbPlace current cursor line at the bottom of the window
<C-e>Scroll down a single line, leaving cursor in place
<C-y>Scroll up a single line, leaving cursor in place

Search Movements

CommandDescription
/patternSearch forward for pattern
?patternSearch backward for pattern
*Search forward for the word under or in front of the cursor
#Search backward for the word under or in front of the cursor
nRepeat last search in same direction
NRepeat last search in opposite direction

Search/Replace

  • :s%/old/new search and replace the first occurrence
  • :s%/old/new/g search and replace all occurrences, without confirmation
  • :s%/old/new/gc search and replace all occurrences, one by one confirmation
  • :s%/old/new/gi search and replace all occurrences, ignoring case
CommandDescription
<C-o>Go to the previous cursor position in the jump list
<C-i>Go to the next cursor position in the jump list

Editing Text

CommandDescription
63i"<Esc>Insert " 63 times in the current line

Deletion

CommandDescription
d{motion}Delete the text that the {motion} command moves over and copy into register.
ddDelete whole current line and copy into register.
DDelete from under the cursor to the end of the line and copy into register.

Changing Text

CommandDescription
c{motion}Delete the text that the {motion} command moves over, copy into register and enter insert mode.
ccDelete whole current line, copy into register and enter insert mode.
CDelete from under the cursor to the end of the line, copy into register and enter insert mode.

Replacing & Deleting Characters

  • x delete the current character under the cursor and copy into register
  • r replace a single character (and then return to Normal mode)
  • R Enter replace mode and start replacing characters by typing until Esc is pressed
  • s delete a character and move into Insert mode
  • S delete current line and move into Insert mode
  • J merge with line below, separated with a single space
  • gJ merge with line below, with no space between
  • . repeat last command

Yank and Put

Switching Case

CommandDescription
~Switch case of character under cursor and move cursor to the right
~{motion}Switch the case of the text that the {motion} command moves over
gu{motion}Change the text that the {motion} command moves over to lowercase
guuMake whole current line lower case
gU{motion}Change the text that the {motion} command moves over to uppercase
gUUMake whole current line upper case

Visual select the text, then U for uppercase or u for lowercase. To swap all casing in a visual selection, press ~ (tilde).

Without using a visual selection, gU<motion> will make the characters in motion uppercase, or use gu<motion> for lowercase.

  • ~ : Changes the case of current character
  • g~~ : Invert case to entire line
  • g~w : Invert case to current WORD
  • guw : Change to end of current WORD from upper to lower
  • guaw : Change all of current WORD to lower
  • guu : Change current line from upper to lower
  • gUw : Change to end of current WORD from lower to upper
  • gUaw : Change all of current WORD to upper
  • gUU : Change current LINE from lower to upper
  • guG : Change to lowercase until the end of document
  • gU) : Change until end of sentence to upper case
  • gu} : Change to end of paragraph to lower case
  • gU5j : Change 5 lines below to upper case
  • gu3k : Change 3 lines above to lower case

Undoing / Redoing

Copying

  • "*y copy to the clipboard register
  • "*p paste from the clipboard register

Cutting

Pasting

Marking

Visual Commands

Color Schemes

Marks and Jumps

Macros

Multiple Files

  • :e file_name open a file in a new buffer
  • :bn move to next buffer
  • :bp go back to previous buffer