2014年9月17日 星期三

關於vim



* 區塊選擇 *[top]

區塊選擇的按鍵意義
v 字元選擇,會將游標經過的地方反白選擇!
V 行選擇,會將游標經過的行反白選擇!
[Ctrl]+v 區塊選擇,可以用長方形的方式選擇資料
y 將反白的地方複製起來
d 將反白的地方刪除掉

參考網頁: http://linux.vbird.org/linux_basic/0310vi.php#vim_v

* 功能鍵替代 *[top]

Esc : [Ctrl]+c


* 大小寫切換 *[top]

為單位:
gUw 小寫變大寫
guw 大寫變小寫

為單位:
gUU 小寫變大寫
guu 大寫變小寫

全文為單位:
gggUG 小寫變大寫
ggguG 大寫變小寫

參考網頁: http://www.diybl.com/course/6_system/linux/Linuxjs/200868/123663.html


* 設定 .vimrc *[top]

關於自動縮排:
set ai "autoindent 但因python會以空格數來區別程式區塊, 所以要拿掉.

關於忽略大小寫:
set ic "ignore case

又, 若無上述設定, 想在查詢時忽略大小寫, 可在最後加上 \c

參考網頁: http://www.shocr.com/linux-vim-search-ignore-case/

關於縮排:

set shiftwidth=4 "switch shift space
set tabstop=4 "set tab stop 這樣縮排位置就會停在前有4個space了

關於顏色:
set t_Co=256 "這樣vimdiff的差異才都可以看清楚.

關於colorscheme:
:e $VIMRUNTIME/colors/ "會開啟 /usr/share/vim/vim72/colors 目錄
" 當中有 blue, darkeblue, default, delek, desert, elflord, evening, koehler, morning, murphy, 
" pablo, peachpuff, ron, shine, slate, torte, zellner 等vim檔

: colorscheme peachpuff "設定成該設定顏色

參考網頁: http://man.chinaunix.net/newsoft/vi/doc/usr_06.html#usr_06.txt

關於gvim預設字型:
set guifont=DejaVu\ Sans\ Mono\ 14 


* ex 功能 *[top]

關於buffer:
1. 列出所有buffer
:ls 
2. 跳至特定某個(如,上述得到的index為2)
:b 2
參考網頁: http://vim.wikia.com/wiki/Buffers; http://vim.wikia.com/wiki/Vim_buffer_FAQ


ls 目前編輯的檔案
:! ls -l %

在 window 環境, 想 grep 目前編輯檔案的某字串
:! c:\cygwin\bin\grep.exe -n "th song" %



* man 功能 *[top]

游標移動到要查詢功能的函式上, 如下面的open:
static int cleanup_illegal_songs(void)
{
int fd, i;
char *sngdir, buf[50];


if ( (fd=open( ILL_CHECKING_FILE, O_RDONLY ))>0){
close(fd);
return 0;
}
...

按 [shift]+[k], 會跳出man open的查詢結果;
如要查特定編號, 則先按數字, 如: 先按 [2] , 再按 [shift]+[k], 會跳出man 2 open的查詢結果.


* diff 功能 *[top]

[[開啟]]

1. 直接執行 vimdiff A B
或 2. 執行 vim 分別開啟 A, B 於垂直分隔視窗, 各自於命令模式打 :diffthis

[[跳轉]]

[c 上一個
]c 下一個

[[離開]]
:set nodiff foldcolumn=0

參考網頁: http://man.chinaunix.net/newsoft/vi/doc/diff.html


* 檔案管理 功能 *[top]

vi 目錄

最上面有簡單的指令說明:

-:go up dir  D:delete  R:rename  s:sort-by  x:exec


. 可配合 Ctrl+v 區塊, 作多個檔案的刪除 (會有確認訊息: [{y(es)},n(o),a(ll),q(uit)], 選a)
. 移動cursor, 按 [enter] 開啟 檔案 或 進入 目錄