Cheat Sheet: VIM

There are many commands in VIM. Those I always use are listed below.

Insert Mode

  • i - insert before the cursor
  • I - insert at the beginning of line
  • a - append after the cursor
  • A - append at the end of line
  • o - open a new line below
  • O - open a new line above
  • ESC - exit insert mode

Delete, Cut & Paste

  • x - delete character
  • dw - delete word
  • dd - delete line
  • yy - copy a line
  • 2yy - copy 2 lines
  • yw - copy a word
  • y$ - copy to end of line
  • p - paste after cursor
  • P - paste before cursor
  • r - replace 1 character
  • :u = undo

Search & Replace

  • /pattern - forward search
  • ?pattern - backword search
  • %s/old/new/g - replace old to new globally

Exiting :

  • :w - write without exit
  • :wq - write and exit
  • :q - exit if no change
  • :q! - exit and discard changes

My VIM Config ~/.vimrc

syntax on
set encoding=utf-8
set showmatch
set ts=4
set sts=4
set sw=4
set autoindent
set smartindent
set smarttab
set expandtab
set paste
colorscheme darkblue

Remarks

  • # if CentOS, sudo yum install vim-enhanced
  • for root user, vi ~/.bashrc
    • alias vi='vim'

Reference

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer