Movement
$
moves the cursor to the last character in a line.
A
moves the cursor to the end of the line and put you in insert mode.
0
moves the cursor to the start of the line.
G
moves to the end of file.
gg
moves to the beginning of a file.
%
moves to corresponding item such as braces and brackets.
Files
:e filepath
open a file to edit.
:e
reload currently open file.
/searchTerm
search for a term in current file.
Buffer
List files in buffer
:ls
Swap files in buffer
Ctrl + Shift + 6
Cut/copy and paste
Using visual selection
Press v
to enter visual mode. Upon entered visual mode, you can move the cursor around to make a selection.
Press d
(delete) to cut or y
(yank) to copy. Move the cursor to the place you want to paste then press p
to paste.
An entire line
Place your cursor over the line you’d like to copy/paste.
Press dd
to cut the entire line; press yy
to copy the entire line.
Move the cursor to the place you’d like to paste and then press p
to paste after the cursor.
Undo and redo
Press u
to undo changes.
Press Ctrl + R
to redo changes.
Manipulating words
In normal mode with your cursor in a word you want to manipulate:
Press daw
to delete the word
Press caw
to delete the word and immediately enter insert mode
Replace text
Press r and then type the text you want to replace the character under the cursor r<text>
Search and replace all instances of a string
In normal mode type
:%s/string_to_replace/replacement_string/g
and hit enter. Vim will instantly find all instances of string_to_replace
and replace with with your replacement_string
.
Search and replace with confirmation
In normal mode type
:%s/string_to_replace/replacement_string/gc
and hit enter. Vim will then find all instances of the string_to_replace
and for each instance ask if you want to replace it with your replacement_string
.
Updated: Dec 08, 2017