<< Back to posts

Notes on Vim Tutor

Cheatsheet of keyboard shortcuts for Vim, learned from vimtutor.

Posted on January 3, 2022 • Tags: vim cheatsheet terminal

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 word
    • e - End of current word
    • $ - End of line
  • Number + Amount
    • <number><amount> - Move number of amount
    • 2w - Move to start of 2 words forward
    • 3e - Move to end of 3 words forward
    • 0 - Move to start of line

Delete

  • x - Delete one character
  • dd - Delete entire line
  • d<motion>, where <motion> is:
    • w - Delete until start of next word
    • e - Delete until end of word
    • $ - Delete until end of line
  • d<number><motion>, where <number> is how many times d is applied
  • c<motion> - Deletes <motion> and puts you in INSERT MODE

Insert

  • A - Append to end of line
  • a - append after cursorj
  • p - Paste last deleted text
  • o - Insert line below cursor and switch to INSERT MODE
  • O - 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 command
  • U - Undo all commands applied to this line
  • Ctrl - R - Redo last command

Cursor Location

  • Ctrl - G - Shows location in file
  • G - Move to end of file
  • gg - Move to start of file
  • <number>G - Move to line #<number>
  • Ctrl - O - Move cursor back to previous location
  • Ctrl - I - Move cursor back to forward location
  • /<phrase> - Search for <phrase>, then hit ENTER
    • n - Go to next result
    • N - 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 of ls and pastes it below cursor

Visual Mode

  • :w <file> - Write selected text to file

  • y - Copy selection
  • p - Paste selection

Help

  • :help - Open help window
    • Ctrl - W Ctrl - W - Switch between windows
  • :help <command> - Get help on <command>