Hobo Chen

Learn Vim II

This tutorial may help you feel happy in the vim world.

The power tool for everyone!

Open and Save

  • vim _name
  • :w _name and absolute dir is allowed : :w ~/Desktop/helloworld.cpp ; when you opened a file created by su but forget to use sudo it can do a lot help ! :-)
  • :x equals :wq, ZZ
  • :saveas _name save as

Insert and Delete

  • i insert; may be the second command you know after installing vim
  • a insert after this character
  • A insert after last character of this line
  • o insert a empty line after this line
  • O insert a empty line before this line
  • x delete the character
  • d delete something, sample use is dd or dw, which means delete the current line or current word

Command of Command

  • u undo
  • ctrl+r redo

Find and Replace

  • /_something to search from the beginninguse
  • n to find nextuse
  • SHIFT+n to find previous
  • [range]s/_target-pattern/_new-pattern/[command]
    • _target-patternregex is allowed
    • range default is this line
      • 1,10 means from line one to line ten
      • 1,$ which is equal to %
    • g means global, only the first target-pattern will be replaced without g
    • c means confirm, asks everytime when about to replace
    • e do not show the error
    • i means igore, which igore whether lowercase or uppercase
    • / in this command could be replaced by #the command will be like :s#hobo#smart#g


  • hjkl :-)
  • gg to the front of this document
  • G to the end of this document
  • ctrl+d Next half page
  • ctrl+n Previous half page
  • ctrl+b Next page
  • ctrl+f Previous page
  • p paste

Advanced Operations

  • . run previous command
  • N<_command> run command N times
    • 100ihobo <_esc> will insert hobo 100times
  • move the cursor
    • % jump to next paired parenthese
    • * # jump to next / previous same word
  • move in a line
    • 0 to head of line
    • ^ to first character but blank
    • $ to tail of line
    • g_ to last character but blank
    • f<_char> to next character which is _char
    • t<_char> to before next character which is _char
    • <_int>f<_char> find the _int-th appeared _char
    • F and T reverse direction of t and f
  • auto completion
    • use YouCompleteMe

Split Window

  • parameters when starting vim
    • vim -On file1 file2 file3 , vertical
    • vim -on file1 file2 file3 , horizontal
  • close c
  • switch ctrl + w, w
  • Split
    • vsp vertical split
    • sp horizontal split

My Vimrc

See: GitHub