vi/vim basic commands


  • vimtutor    (Basic tutorial)
  • vi  -r  file    (Start vi and edit file in recovery mode from a system crash)
  • :wq             (Save and Exit)
  • :q!               (Exit without save)
  • :w file2       (Save file with a different name)
  • Esc              (Exit insert mode and switch to command mode ‘:‘)
  • j -> Down; k-> Up; h-> Left; l-> Right
  • g=GG      (‘=’ Correct/Format alignment or indention; ‘g’ : start; ‘GG’: End)
  • :e     (Open and create

Move the cursor:

  • gg or H -> Move to the first line
  • G -> Move to the last line
  • 0|^ -> Move to the beginning of the current line
  • $ -> Move to the end of the current line
  • w -> Move to the next word
  • b -> Move to the previous word

Insert or Append:

  • i or Insert key-> Insert
  • I -> Insert at the begning of current line
  • a -> Append at the cursor
  • A -> Append at the end of the line
  • o -> Insert new line below current line
  • O -> Insert new line above current line

Copy, Paste and Delete:

  • yy -> Copy current line (3y to copy three lines)
  • dd -> Cut / Delete current line
  • p -> Paste copied or cut line  (3p three times copied line)
  • x -> Delete character
  • dw -> Delete word
  • cw -> Change word
  • D -> Delete the rest of the line
  • u -> undo
  • ctr+r-> redo

Search and Replace:

  • :99                 (Go to line number 99)
  • /pattern -> Search a pattern or word or string
  • ?pattern -> Search pattern backward
  • :%s/cat/dog               Without ending “/”, will replace just first occurrence
  • :%s/cat/dog/g ->        g: global; Replace all occurrences of cat with dog
  • :%s/cat/dog/gc ->  -> c: Interactive
  • :%s/\<cat\>/dog/gi->  i: Ignore case; Replace all cat words (<cat>) ignoring case
  • :1,3s/cat/dog/g -> Replace all occurrences of cat with dog from 1st to 3rd line
  • n-> Move to the next pattern
  • N-> Move to the previous pattern

Line, Word and Character count:

  • :! wc % -> Counts lines, word and characters
  • :map <leader>e :./<cr>         (Map leader key ‘\‘ -> \+e to execute ./

Color or theme change:

  • :color desert -> set color
  • :set hlsearch
  • ~\.vimrc
    • set number             (show line numbers)
    • synax on
    • set tabstop=4
    • set autoindent
    • ctr+shift+g            (Show current line and column number)

About Ishtiaque

I am IBM Certified Infrastructure Systems Architect, Linux Foundation Certified System Administrator, Oracle Certified Programmer in Java and Web Component Developer, and TOGAF 9 certified with over 10 years of support and development experience in IBM middleware software and Java. Additionally, have a sound grip in databases and OpenStack administration. I hold the following certifications: IBM Certified Infrastructure Systems Architect Linux Foundation Certified System Administrator (LFCS) TOGAF 9 Certified Oracle Certified Expert, Java EE6 Web Component Developer Oracle Certified Professional – Java 6 Programmer ITIL v3 Foundation Certified IBM Certified Solution Architect – Cloud Computing Infrastructure V1 IBM Certified System Administrator – WebSphere Portal V8, V7, V6.1, V6 IBM Certified System Administrator – WebSphere Application Server V7, V6.1 IBM Certified System Administrator – AIX V7 IBM Certified System Administrator – WebSphere MQ V7 IBM Certified Deployment Professional – Business Process Manager Advanced V7.5 IBM Certified Solution Advisor – Cloud Computing Architecture V3 IBM Certified Solution Developer – WebSphere Portal V5.1
This entry was posted in LFCE, LFCS, Linux and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s