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 boardnvim .
open the cwd
Exiting
Command | Description |
---|---|
:w | Write (save) file without exiting |
:wa | Write (save) all open files without exiting |
:q | Quit but fail if unsaved changes exist |
:qa | Quit All but fail if unsaved changes exist |
:q! / ZQ | Quit and discard unsaved changes |
:wq / :x | Write (save) and quit |
ZZ | Write (save) and quit |
:wqa | Write (save) and quit on all open files |
Changing Vim Modes
Command | Description |
---|---|
i | Enter INSERT mode |
a | Enter INSERT mode after the cursor (think: append) |
A | Enter INSERT mode at the end of the line (think: Append) |
o | Open new line below the cursor and enter INSERT mode |
O | Open new line above the cursor and enter INSERT mode |
v | Enter character-wise VISUAL mode |
V | Enter line-wise VISUAL mode |
<C-q> | Enter block-wise VISUAL mode (Windows) |
<C-v> | Enter block-wise VISUAL mode (MacOS) |
: | Enter COMMAND-LINE mode |
R | Enter REPLACE mode |
ESC | Go back to NORMAL mode from other modes |
u | Undo 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
Command | Description |
---|---|
h | Move cursor left |
j | Move cursor down |
k | Move cursor up |
l | Move cursor right |
Same-Line Navigation
Command | Description |
---|---|
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 Fx | Find next/previous occurrence of character ‘x’ |
tx and Tx | Go towards next/previous occurrence of character ‘x’ |
; and , | Repeat previous f , F , t , or T movement forwards / backwards |
Word Movements
Command | Description |
---|---|
w | Move cursor forwards to start of word |
W | Move cursor forwards to start of WORD |
b | Move cursor backwards to start of word |
B | Move cursor backwards to start of WORD |
e | Move cursor forwards to end of word |
E | Move cursor forwards to end of WORD |
ge | Move cursor backwards to end of word |
gE | Move cursor backwards to end of WORD |
Sentence Movements
Command | Description |
---|---|
) | Move cursor to next sentence |
( | Move cursor to previous sentence |
Paragraph Movements
Command | Description |
---|---|
} | Move cursor to next paragraph |
{ | Move cursor to previous paragraph |
Moving To Specific Lines
Command | Description |
---|---|
gg | Move cursor to first line of document |
G | Move cursor to last line of document |
{number}G | Move cursor to line {number} |
{number}j | Go {number} lines down |
{number}k | Go {number} lines up |
{number}% | Go to {number}% of the file |
H | Move cursor to line at the top of the window |
M | Move cursor to the line at the middle of the window |
L | Move cursor to the line at the bottom of the window |
Screen Related Cursor Movements
Command | Description |
---|---|
<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
Command | Description |
---|---|
zz | Place current cursor line in the middle of the window |
zt | Place current cursor line at the top of the window |
zb | Place 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
Command | Description |
---|---|
/pattern | Search forward for pattern |
?pattern | Search 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 |
n | Repeat last search in same direction |
N | Repeat 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
Navigating The Jump List
Command | Description |
---|---|
<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
Command | Description |
---|---|
63i"<Esc> | Insert " 63 times in the current line |
Deletion
Command | Description |
---|---|
d{motion} | Delete the text that the {motion} command moves over and copy into register. |
dd | Delete whole current line and copy into register. |
D | Delete from under the cursor to the end of the line and copy into register. |
Changing Text
Command | Description |
---|---|
c{motion} | Delete the text that the {motion} command moves over, copy into register and enter insert mode. |
cc | Delete whole current line, copy into register and enter insert mode. |
C | Delete 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 registerr
replace a single character (and then return to Normal mode)R
Enter replace mode and start replacing characters by typing untilEsc
is presseds
delete a character and move into Insert modeS
delete current line and move into Insert modeJ
merge with line below, separated with a single spacegJ
merge with line below, with no space between.
repeat last command
Yank and Put
Switching Case
Command | Description |
---|---|
~ | 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 |
guu | Make whole current line lower case |
gU{motion} | Change the text that the {motion} command moves over to uppercase |
gUU | Make 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 characterg~~
: Invert case to entire lineg~w
: Invert case to current WORDguw
: Change to end of current WORD from upper to lowerguaw
: Change all of current WORD to lowerguu
: Change current line from upper to lowergUw
: Change to end of current WORD from lower to uppergUaw
: Change all of current WORD to uppergUU
: Change current LINE from lower to upperguG
: Change to lowercase until the end of documentgU)
: Change until end of sentence to upper casegu}
: Change to end of paragraph to lower casegU5j
: Change 5 lines below to upper casegu3k
: 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