2008年12月18日 星期四

vim related commands

VIM字串搜尋與取代
s(substitute)指令可搜尋某行列範圍。
g(global)指令則可搜尋整個編輯緩衝區的資料。
s 指令以第一個滿足該條件的字串為其取代的對象,若該行有數個滿足該條件的字串,也僅能取代第一個,若想取代所有的字串則需加上g參數。
c 詢問
:1,$s/old/new/g 將檔案中所有的『old』改成『new』。
:10,20s/^/ / 將第10行至第20行資料的最前面插入5個空白。
:%s/old/new/g 將編輯緩衝區中所有的『old』改成『new』。
:1,$s/$/ \\/c 在所有行後面加" \",每次都詢問
:1,$s/ /\r/c 把所有空白都變成換行,每次都詢問

:s/ *$//g刪掉以空白結尾的空白
:g/^$/d 將檔案中所有的空行刪掉
:10,20g/^$/d 將10-20行中空行刪掉

:g/XXXXXXX/ .,/YYYYYYYYYYY/d 刪掉XXXX到YYYY間多行
https://vi.stackexchange.com/questions/5265/how-to-delete-a-multi-line-match

gg (move to 1st line)
G (move to last line)

column select
^v (move arrow key to select area)

column delete
column select + d

column insert
column select + [shift]+i

delete word
dw

Line number
:set nu
:set nonu

Ignore Case (not case sensitive)
:set ic
:set noic

Disable indent
:set paste
:set nopaste

:e <files>

vsplit
split
^w<arrowkey>
:b<number>

shift+% 找對應的括號
shift+8 找現在cursor所在的word

tags
:set tags=tags
^]
^t
:ts or g]
:tag /search-string



Linux vi and vim editor: Tutorial and advanced features (include ctags)
http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html
http://freehaha.blogspot.com/2007/06/vim-code.html
http://zcecil.net/?p=160
http://vim.sourceforge.net/tips/tip.php?tip_id=330
http://www.uic.edu/depts/accc/software/unixgeneral/vi101.html

Column Edit Mode in VI
http://pivotallabs.com/users/brian/blog/articles/350-column-edit-mode-in-vi

我的 VIM 之路
http://t.bsdx.org/2007/06/15/%E6%88%91%E7%9A%84-vim-%E4%B9%8B%E8%B7%AF/

沒有留言: