Vim Cheat Sheet

This article will be continuously updated.

Moving around

  • h j k l move left up down right ONE character.
  • 5 h move 5 characters towards left.
  • gg jump to the first line.
  • 5 G jump to the fifth line.


  • ~ toggle case of ONE character, or N continuous characters with motion. like 4u to change hello to HELLo (cursor at h)

FUO (Frequently Used Operations)

  1. How to make HTML soup more tiny in vim ?

    1. first join all the lines - ggVGgJ
    2. Now break tags to new lines - :%s/>\s*</>\r</g
    3. Now set filetype - :set ft=html (you can do this before too)
    4. Now Indent - ggVG=

    original answer:

  2. how to open the directory of the current open file

    use :Sex or :Vex command. Sex refers to Sexplore aka Split&Explore current file's directory. V for Vertical.

  3. show file path of the current open file CTRL-G (Not Shift-G, which is jump to the very bottom of the file)


no comments