Monday, 27 April 2015

Essential vim commands


Basic Commands:
  • :e file_name     ----------------->    Open file_name for edition    
  • :w                    ----------------->    Save file
  • :q                     ----------------->    Exit from Vim
  • :q!                    ----------------->    Quit without saving
  • :x                     ----------------->     Write file and exit (If changes has been made)
  • :sav file_name ----------------->    save file as file_name

Moving in the file

  • k or Up Arrow       ----------------->   move the cursor up one line
  • j or Down Arrow   ----------------->   move the cursor down one line
  • e                            ----------------->   move the cursor to the end of the word
  • b                            ----------------->  move the cursor to the begining of the word
  • 0                            ----------------->  move the cursor to the begining of the line
  • G                           ----------------->  move the cursor to the end of the file
  • gg                         ----------------->   move the cursor to the begining of the file

 Search

  • /word           ----------------->    Search word from top to bottom
  • ?word          ----------------->    Search word from bottom to top
  • /\cstring       ----------------->   Search STRING or string, case insensitive
  • /r[io]se         ----------------->   Search rise or rose
  • /\< the         ----------------->    Search the, theatre or then

Search and  Replace 

  • :%s/hai/hello/g     ----------------->  Find the occurence of "hai", in all line and replace it with "hello".
  • :s/hai/hello/g        ----------------->  Find the occurrence of "hai", in the current line only, and replace it with "hello"
  •  :%s/hai/hello/gc  ----------------->  Change each "hai" to "hello", but it will ask the confirmation first
  • :%s/hai/hello/gci  ----------------->  Change each "hai" (case sensitive) to "hello", but ask for confirmation
  • :%s/hai/hello/gcI  ----------------->  Change each "hai" (case insensitive) to "hello", but ask for confirmation
 
Copy and Pasting

  • v heighlight one charecter at a time.
  • V one line at a time.
  • y yank text into copy buffer.
  • p paste text after the current line.
  • P paste text on the current line.

No comments:

Post a Comment