Wednesday 4 December 2013

Important vim commands

  • :! for running a command outside the vim.                   eg. :!pwd
  • set smartindent
  • Ctrl x + Ctrl l                    for autocompletion of entire line
  • Replacing in a line: s/foo/bar/g will replace each occurence of foo by bar.
  • Replacing in a line: s/foo/bar/gc will replace each occurence of foo by bar, but ask for confirmation.
  • Replacing in a file: %s/foo/bar/gc will replace each occurence of foo by bar, but ask for confirmation.
  • But if use s/foo/bar it then it will replace the first occurance of foo by bar in the line.
  • Use arrow keys to get the previous command.
  • Use :ab mail praveendhinwa@gmail.com etc kind of abbreviations.
  • >> and << for indentation
  • sh: temporary returns to unix.
  • e filename: opens the file with given filename.
  • browse e: graphical file opening.
  • use tab for completion of half command too 
  • :g/string/d delete all lines containing string
  • :v/string/d delete all lines not containing string.
  • 2,15s/foo/bar/g delete all occurences of foo by bar from line 2 to 15.
  • * for searching the word under the cursor currently.
  • /word Searching from top
  • ?word Searching from bottom to top.
  • /f[ao]r will search for far and for both.
  • yy for copying a single line.
  • 2yy for copying two lines.
  • y for copying the selected text.
  • p for pasting the clipboard content.
  • shift + [ or ] for moving from the end of functions to start and vice versa.
  • gg for moving the cursor to start of line
  • G for moving the cursor to the end of line.
  • :17 to move the cursor to line numbered 17.
  • 0 Move the cursor to beginning of the line
  • b for start of the word
  • e for moving to end of the word
  • cc for changing an entire line.
  • Generating text to html code.     :%TOhtml
Mapping in Vim:
  • :imap ;so System.out.println() , Whenever you will type ;so, it will autcomplete to System.out.println() with cursor between the paranthesis.

References


No comments:

Post a Comment