All of the Vim commands and tricks that you actually need to know. Hotkeys, tips, and tricks for beginners of all types.
What Is Vim?
Vim is a powerful text editor that allows you to edit text using only the keyboard – no mouse required. This helps to improve efficiency, particularly for software engineers, programmers and developers.
Vim comes with an array of default shortcuts, but you can also edit/add new commands to customize it using the .vimrc file.
Vim Commands Cheat Sheet, Copy-Pasteable
Exiting Vim
:w - Write (Save)
:wq - Write and quit
:q - Quit, fails if unsaved
:q! - Quit, even if unsaved
Modes
ESC - Return to normal mode
i - Insert at cursor position
a - Insert after cursor position
o - Insert on line below cursor
v - Enter visual mode
ctrl+v - Enter visual mode (vertical)
V - Enter visual mode (full lines)
Toggling Case
u [in visual mode] - To lowercase
U [in visual mode] - To uppercase
Undo/Redo
u - Undo
ctrl+r - Redo
Movement
$ - Jump to end of line
^ - Jump to start of line
h - Move left
j - Move down
k - Move up
l - Move right
H - Move to top of screen
M - Move to middle of screen
L - Move to bottom of screen
gg - Move to start of file
G - Move to end of file
420gg - Move to line 420
w - Jump to start of next word
b - Jump to start of prev word
Search
/something - Search for string
n - Jump to next match
N - Jump to prev match
/something\c - Case insensitive search
Copy-Pasting
y [in visual mode] - Copy highlighted text
yy - Copy the current line
d [in visual mode] - Cut highlighted text
dd - Cut the current line
Ctrl+Shift+V - Paste from external clipboard
Find-and-Replace
- Find and Replace All in Document
:%s/find/replace/g
- Find and Replace All on Current Line
:s/find/replace/g [in visual mode]
- Find and Replace All in Highlighted Section
:'<,'>s/find/replace/g [in visual mode]
- Find and Replace All in Document
:%s/address/replace/g
Important Regular Expression (REGEX) Characters
. - Any single character
* - Up to unlimited characters