<< Back to posts
Notes on Vim Tutor
Cheatsheet of keyboard shortcuts for Vim, learned from vimtutor.
I’ve always been intimidated by vim
. After taking MIT’s Missing Semester Course (a free online course that I’d highly recommend), I learned about a built-in utility called vimtutor
that automatically comes installed with vim
.
vimtutor
is a series of interactive tutorials that teach you the basics of vim
.
While it won’t make you fluent, it gives you enough grounding to say the equivalent of “Where’s the bathroom?” and “I’d like water, please” in vim
-speak.
The tutorial is a bit long, so here are my summary notes from going through the exercises:
Normal Mode
Format for commands:
<operator><number><motion>
Move
- Directional
<number>h
- Left<number>
times<number>j
- Up<number>
times<number>k
- Down<number>
times<number>l
- Right<number>
times
- Amount
w
- Start of next worde
- End of current word$
- End of line
- Number + Amount
<number><amount>
- Movenumber
ofamount
2w
- Move to start of 2 words forward3e
- Move to end of 3 words forward0
- Move to start of line
Delete
x
- Delete one characterdd
- Delete entire lined<motion>
, where<motion>
is:w
- Delete until start of next worde
- Delete until end of word$
- Delete until end of line
d<number><motion>
, where<number>
is how many timesd
is appliedc<motion>
- Deletes<motion>
and puts you in INSERT MODE
Insert
A
- Append to end of linea
- append after cursorjp
- Paste last deleted texto
- Insert line below cursor and switch to INSERT MODEO
- Insert line above cursor and switch to INSERT MODE
Copy
y<motion>
- Copies<motion>
p
- Paste
Replace
r<x>
- Replace current character with<x>
R
- Replace characters until hit ESC:s/<old>/<new>
- Replace first occurence of<old>
with<new>
in line:s/<old>/<new>/g
- Replace every occurrence in line:%s/<old>/<new>/g
- Replace every occurrence in entire file
Undo / Redo
u
- Undo last commandU
- Undo all commands applied to this lineCtrl - R
- Redo last command
Cursor Location
Ctrl - G
- Shows location in fileG
- Move to end of filegg
- Move to start of file<number>G
- Move to line #<number>
Ctrl - O
- Move cursor back to previous locationCtrl - I
- Move cursor back to forward location
Search
/<phrase>
- Search for<phrase>
, then hit ENTERn
- Go to next resultN
- Go to previous result
:set ic
- Ignore case:set noic
- Disable ignore case
:set hls is
- Highlight matches:nohlsearch
- Disable highlighting matches
%
- Jump to matching parenthesis, i.e. ({[]})
External Commands
:!<command>
- execute<command>
:!ls
- List files:!rm <file>
- Delete<file>
:w <file>
- Write to<file>
:r <file>
- Reads text from<file>
and pastes it below cursor:r !ls
- Reads output ofls
and pastes it below cursor
Visual Mode
-
:w <file>
- Write selected text to file y
- Copy selectionp
- Paste selection
Help
:help
- Open help windowCtrl - W Ctrl - W
- Switch between windows
:help <command>
- Get help on<command>