Vim Cheat Sheet and Syntax Highlighting

Vim Cheat Sheet

Saving and Exiting Vim

  • :wq save changes and exit
  • :q! quit changes and exit
  • :q quit and exit provide no changes
  • :x save changes and exit

Moving around lines

  • Use arrow keys to move around
  • For laptop users use hjkl:
  • h left
  • l right
  • k up
  • j down

  • <ctrl>+F page up
  • <ctrl>+B page down
  • e end of the word (forward)
  • b begin of the word (backward)
  • w beging of the word (forward)
  • 0 begin of the line
  • $ end of the line
  • H first line of screen
  • L last line of screen
  • :n goto line number

Text Editing

  • i inset before cursor
  • a append after cursor
  • A append to the end of current line
  • o open an new line below cursor and inset
  • C change the rest of current line
  • r replace current character e.g. rd replace current character to d


  • x delete cha under cursor
  • dw delete word
  • dd delete current line
  • d$ delete the rest of the line form cursor

Copy and Paste

  • yy copy current line
  • dd delete current line or cut current line
  • p paste

Copy and Paste in Visual Mode

  • v enter visual mode, highlight the text
  • y copy highlighted
  • x delete highlight
  • p paste

Undo and Redo (normal mode)

  • u undo
  • U undo all the changes for the current line
  • <ctrl>+r redo

Syntax Highlighting

Enable Syntax Highlighting

  • :syntax on

To enable autoindent

  • :set autoindent

To enable line number

  • :set number

To see the default file type

  • :set filetype

To set filetype manually:

  • :set filetype=perl
  • :set filetype=php
  • :set filetype=python

To configure syntax highlighting permanently, go to the configuration file under vim ~/.vimrc

Add the following:
syntax on
set number
set autoindent

Note: The previous tips should worked on Linux, Max OS X and Unix. If it doesn't work please refer to the man page or check the documentation of vim for the particular OS.



Popular posts from this blog

Revive Old Mac Mini (2009) with Linux

Configure Unattended Upgrades on Raspberry Pi

Install and Configure RealVNC in Linux Ubuntu 18.04 LTS