About Vim


Vim的第一个版本由布萊姆·米勒在1991年发布。最初的简称是Vi IMitation,随着功能的不断增加,正式名称改成了Vi IMproved。现在是在开放源代码方式下发行的自由软件。

1. Content List

2. Vim Tips

2.1. Show Line Numbers

in Command Mode

:set number
:set nu
:set nonumber/nonu

2.2. Search Topics

2.2.1. 搜索区分大小写

in Command Mode

:set ignorecase
:set ic
:set noignorecase/noic

  Search STRING forward :   / STRING.
  Search STRING backward:   ? STRING.

  Repeat search:   n
  Repeat search in opposite direction:  N  (SHIFT-n)

2.2.3. Replace

Same as with sed, Replace OLD with NEW:

 First occurrence on current line:      :s/OLD/NEW
 Globally (all) on current line:        :s/OLD/NEW/g 

 Between two lines #,#:                 :#,#s/OLD/NEW/g
 Every occurrence in file:              :%s/OLD/NEW/g Replace by a newline

https://stackoverflow.com/questions/71323/how-to-replace-a-character-by-a-newline-in-vim :s/OLD/\r/g

2.3. Run command in Vim

in Command Mode


Press ENTER or type command to continue

2.4. Toggle auto-indenting for code paste

add in Vimrc

" press F2 to change autoindent setting
nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
set showmode

3. Skills

3.1. 乱码问题


export LC_CTYPE=zh_CN.UTF-8
-bash: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8)

参考: http://ubuntuforums.org/showthread.php?t=1720356


apt-get install --reinstall language-pack-zh-hans
locale-gen zh_CN
export LC_CTYPE=zh_CN.UTF-8

3.2. Vim Can't Save File (E212)


##This will ask you for the root password
:w !sudo tee %
##Then type (L)oad at the prompt, to re-load the file after it is saved

3.3. 禁止黏贴时的自动缩进

:set paste

4. Reference


MainWiki: Vim (last edited 2011-12-07 17:33:38 by twotwo)