robturtle
10/8/2017 - 12:41 AM

.vimrc

compilation options

  • +clipboard to support system clipboard (Useless if you're on a server)
  • +mouse to support mouse (including scrolling)

Check out compiling vim from source to install the latest version.

General rules

  1. all vim commands can have a number prefix
  2. all vim operators(e.g. remove/move/copy) will accept a range
  3. if x is the normal function, X is its super function

Navigation key (used to move the cursor)

  • hjkl
  • w -- word head
  • b -- back word head
  • e -- next word end
  • f -- find (; to next one)
  • t -- till
  • ] -- next paragraph
  • [ -- prev paragraph

Selection key

形容词+名词

形容词:

  • i -- in
  • a -- one

名词:can be extended by plugin

  • " -- ""
  • ' -- ''
  • ) -- ()
  • ] -- []
  • } -- {}
  • p -- paragraph
  • w -- word

to enter INSERT

  • o -- other line -- 另起一行
  • a -- pend a line -- 在后面插入
  • i - insert -- 在前面插入
  • s -- substitute

OPERATOR

NOTE: rule 3 applies to operators

rule 4. if x is normal function, xx is super function

operators require a range, it could be either:

  1. operator + navigation/selection key
  2. selection + operator (equivalent to '<,'>operator)
  • g -- goto (35G: goto line 35)
  • c -- change
  • d -- delete
  • y -- copy (use p to paste)
  • v -- visual mode

no range operator

those operators don't need range:

  • x -- delete current char
  • r -- replace current char

demo

By using dw, we take d as verb and w as noun, making a meaningful sentense: "delete a word".

Bulk replacing

  • :[%|$start,$end]s/tosearch/toreplace[/g]
  • % to search crossing the whole file
  • . means current line
  • +3 means to the next 3 lines
  • / is not the only separator. you could use anything you want (typically #)
  • g to replace globally (without % it means global crossing the line)

misc

  • u -- undo
  • ^r -- redo
  • / -- search (n for next search result, N for prev)
" add the following paragraph to Vim_utils

" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
            \ if line("'\"") > 0 && line("'\"") <= line("$") |
            \ exe "normal! g`\"" |
            \ endif
" Remember info about open buffer on close
set viminfo^=%