VI Cheat Sheet


This isn’t an extensive list.
I’m not a heavy vi user, so I often forget basic commands I want to use. So, this is a list of those commands.

 

Split screen

  • vertically
    CTRL + w and v
  • horizontally
    CTRL + w and s

Move between screens

  • down
    CTRL + w and j
  • up
    CTRL + w and k
  • right
    CTRL + w and l
  • left
    CTRL + w and h

Move cursor to …

  • specific line
    <line number> + gg
  • top of the file
    gg
  • bottom of the file
    G
  • end of the line
    $

Scroll page

  • up
    CTRL + b
  • down
    CTRL + f

Copy and paste multiple lines

  1. Press V (to enter VISUAL LINE mode)
  2. Select the lines you want to copy
  3. Press y (or d for cut instead of copy)
  4. Move the cursor to where you want to paste the lines
  5. Press p to paste

Comment out multiple lines

  1. Press CTRL + v (to enter VISUAL BLOCK mode)
  2. Move the cursor to select the lines you want to comment out
  3. Press I (to enter INSERT mode)
  4. Type # (in case of shell script)
  5. Enter ESC

Save file as …

  • :w <file name>

Open file

  • :e <file name>

Search selected word

  • Search forward
    *
  • Search backward
    #

Show/hide line number

  • Show
    :set number
  • Hide
    :set nonumber