版權聲明

所有的部落格文章都可以在右邊[blog文章原始檔案]下載最原始的文字檔案,並依你高興使用 docutil 工具轉換成任何對應的格式方便離線閱覽,除了集結成書販賣歡迎任意取用,引用

VIM 好用 Plugin 介紹

VIM 好用 Plugin 介紹

Surround

Surround 用來處理程式語言常常用到成對的符號,如括號等。

安裝

下載位置 http://vim.sourceforge.net/scripts/script.php?script_id=1697

下載完畢直接在 .vim/ 解開就ok了。

要建立說明就在 Vim/GVim 中執行 :helptags ~/.vim/doc

  • Windows 使用者自行將 .vim/ 改成對應的 vimfiles/

使用方式

刪除

刪除主要的命令是 ds (normal mode),游標在欲處理字串中任何一個位置都行。

Text             Command     New Text
--------------   ----------  -------------
'Hello World'    ds'         Hello World
(123+4)/5        ds(         123+4/5
<div>a</div>     dst         a

Change

改變既有的成對符號,主要命令格式cs[cur][ch],[cur]代表目前符號,[ch]代表 欲改變的符號。

Text              Command    New Text
---------------   -------    -----------
"Hello |world!"   cs"'       'Hello world!'
"Hello |world!"   cs"<q>     <q>Hello world!</q>
(123+4|56)/2      cs)]       [123+456]/2
(123+4|56)/2      cs)[       [ 123+456 ]/2
<div>foo|</div>   cst<p>     <p>foo</p>
fo|o!             csw'       'foo'!
fo|o!             csW'       'foo!'

(| is the position of cursor in these examples)

Add

加入成對符號的主要指令是ys

Text              Command      New Text
---------------   -------      -----------
Hello w|orld!     ysiw)        Hello (world)!
Hello w|orld!     csw)         Hello (world)!
fo|o              ysiwt<html>  <html>foo</html>
foo quu|x baz     yss"         "foo quux baz"
foo quu|x baz     ySS"         "
                                   foo quux baz
                               "

(| is the position of cursor in these examples)

visual mode

最後~ visual mode 可以使用s命令來增加成對符號。

GetLatestVimScripts

GetLatestVimScripts 自動更新所有plugin!

安裝

下載後依順序輸入下列指令 (windows 請確認 gunzip 和 tar 都在你的環境中)

1. vim getscript.vba.gz
   :so %
   :q
2. Unix:
      cd ~/.vim/GetLatest
   Windows:
      cd ..wherever..\vimfiles\GetLatest
3. mv GetLatestVimScripts.dist GetLatestVimScripts.dat

使用方式

輸入指令:

:GetLatestVimScripts
-or-
:GLVS

說明

vimball 這種安裝方式沒有硬性規定所有 plugin 遵守,就算遵守vimball也不一定支援 GetLatestVimScripts 所以目前為止,還是不可能像其他套件管理軟體一樣,一個指令ok 。

執行指令以後還是需要到 .vim/GetLatest 瞧瞧並手動安裝。

Align

Align 處理文字對齊的問題,比如 source code 的宣告,賦值,或是註解等等。

安裝

下載後依順序輸入下列指令 (windows 請確認 gunzip 和 tar 都在你的環境中)

vim align.vba.gz
:so %
:q

使用方式

這邊介紹比較簡單的使用方式,詳情請參考說明檔 (:help Align)

對齊賦值 (\t=)

\t=

比如下面的 source code:

void test()
{
    int a=12;
    float some_scale = 1.22;
    void *p = null;
    char n = '\0';
}

將這四行賦值運算用 visual 選取 (normal mode 按 v),然後輸入 \t= 你會看到你要的結果。

void test()
{
    int a            = 12;
    float some_scale = 1.22;
    void *p          = null;
    char n           = '\0';
}

\t

\t 除了剛剛看過的 \t= 外可以有多種不同的運用比如

  • \t, 代表對齊逗號
  • \t| 對齊 |
  • \tsp 對齊空白字元

等等

宣告 \adec

C 或類似語法的程式語言宣告對齊。

void test()
{
    int a;
    float some_scale;
    void *p;
    char n;
}

一樣用 visual mode 選取想要對齊的區域,在輸入 \adec。

void test()
{
    int    a;
    float  some_scale;
    void  *p;
    char   n;
}

Matchit

Matchit 超推薦這個東西,在把玩 C 語言的時候利用 % 指令在括弧間跳躍是相當爽的, 安裝這鬼玩意後,html的tag也可以 % 跳躍了 #ifdef #endif 也可以用 % 跳躍了..

安裝

下載後直接靠拷貝到 .vim 目錄解壓縮即可。

記得使用 :helptags ~/.vim/doc 建立說明文件。

Windows 使用者就把 .vim 換成你的 vimfile 目錄即可。

FuzzyFinder

FuzzyFinder 這玩意也是最近很有名,可以讓 Vim 像 emacs 一樣快速的開檔案,buffer或是tag

安裝

拷貝到.vim/ 目錄下解開即可。

使用

FuzzyFinder 相當複雜這邊稍微介紹一下比較常用的。

開啟模式

  1. Enter 最簡單的在目前視窗開啟選擇的項目
  2. <C-j> 在水平分割視窗開起
  3. <C-K> 垂直分割視窗中開啟
  4. <C-l> 新 tab 開啟

相關介紹 http://rickey-nctu.blogspot.com/2009/02/vim-fuzzyfinder.html

沒有留言:

Related Posts with Thumbnails