VIM shell 整合
VIM 和 shell 整合相關範例
讀取 shell 命令(ls)的輸出:
:r !ls
上面指令會將 ls 的輸出印到目前cursor位置。
插入時間:
:r !date :r !date /T (windows)
keep simple
VIM 和 shell 整合相關範例
讀取 shell 命令(ls)的輸出:
System Message: WARNING/2 (/Volumes/austin.jan/Documents/note/vim_shell_integrate.rst, line 9)
Literal block expected; none found.
:r !ls
上面指令會將 ls 的輸出印到目前cursor位置。
插入時間:
System Message: WARNING/2 (/Volumes/austin.jan/Documents/note/vim_shell_integrate.rst, line 15)
Literal block expected; none found.
:r !date :r !date /T (windows)
必要條件: Vim7 以上
確認你的 VIM 版本是有支援 python 的
這討論串有相關說明 http://code.google.com/p/macvim/issues/detail?id=101 到此為止是 snap50 版本是已經建立好的 macvim 使用 python 2.5
windows 要自己編譯 vim,其實也超級簡單的下載->編譯就好了,source code可以在 官方網頁下載。 這邊介紹使用 Visual Studio 編譯的指令 .. code-block:: bash
nmake -f make_mvc.mak FEATURES=HUGE GUI=yes OLE=yes MBYTE=yes IME=yes GIME =yes PYTHON=C:python25 DYNAMIC_PYTHON=yes PYTHON_VER=25 CSCOPE=yes
確認 vim 有支援 python
:python import sys :python print sys.version
Contents
Surround 用來處理程式語言常常用到成對的符號,如括號等。
下載位置 http://vim.sourceforge.net/scripts/script.php?script_id=1697
下載完畢直接在 .vim/ 解開就ok了。
要建立說明就在 Vim/GVim 中執行 :helptags ~/.vim/doc
刪除主要的命令是 ds (normal mode),游標在欲處理字串中任何一個位置都行。
Text Command New Text -------------- ---------- ------------- 'Hello World' ds' Hello World (123+4)/5 ds( 123+4/5 <div>a</div> dst a
改變既有的成對符號,主要命令格式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)
加入成對符號的主要指令是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 可以使用s命令來增加成對符號。
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
vimball 這種安裝方式沒有硬性規定所有 plugin 遵守,就算遵守vimball也不一定支援 GetLatestVimScripts 所以目前為止,還是不可能像其他套件管理軟體一樣,一個指令ok 。
執行指令以後還是需要到 .vim/GetLatest 瞧瞧並手動安裝。
Align 處理文字對齊的問題,比如 source code 的宣告,賦值,或是註解等等。
這邊介紹比較簡單的使用方式,詳情請參考說明檔 (:help Align)
\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';
}
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 超推薦這個東西,在把玩 C 語言的時候利用 % 指令在括弧間跳躍是相當爽的, 安裝這鬼玩意後,html的tag也可以 % 跳躍了 #ifdef #endif 也可以用 % 跳躍了..
FuzzyFinder 這玩意也是最近很有名,可以讓 Vim 像 emacs 一樣快速的開檔案,buffer或是tag
拷貝到.vim/ 目錄下解開即可。
FuzzyFinder 相當複雜這邊稍微介紹一下比較常用的。
相關介紹 http://rickey-nctu.blogspot.com/2009/02/vim-fuzzyfinder.html
檢查一下 ~/.vim/ftplugin 下面有沒一個 python_fn.vim 的vim script檔案? 如果有的話,很開心的告訴你他裡面覆蓋了一個熱鍵 ]c (Select current class) 剛好和 vim diff 的下一個 different 熱鍵相同,所以假如你正在使用 vimdiff 又發現 ]c 怪怪的,請檢查一下。
有時後下載了 Vim script 後明明就有把script說得說明檔丟到 ~/.vim/doc 下面,可是 還是沒法在vim中查到相關說明?
很有可能是你只copy進去沒有建立tag,試試下面指令:
:helptags ~/.vim/doc
這個問題就我的使用習慣大概每半年就會出現一次。。
人老了???
Incremental search : 輸入收尋指令 (/) 後輸入要收尋的字串或是pattern時 會即時隨著輸入反應在編輯畫面上,請在 .vimrc 加上:
set incsearch
Highlight search : 輸入收尋指令後,會自動將文件所有符合項目 highlight:
set hlsearch
參考至 (VIM不可不知10大功能) http://www.oualline.com/10/top_10.html
jump有一個jump list管理
Ctrl-O goto older (上一步) Ctrl-I goto newer (下一步) gg 檔頭 G 檔尾 gd goto local define gf goto file (cursor) gD goto global define ctrl-] jump to tag ctrl-T back tag ju show jump list
Ctrl-f page up Ctrl-b page down 0 home $ end ^ 目前行第一個字
H Top of screen M middle of screen L bottom of screen
w next word W next word (include _-.等連結符號) b pre word B pre word (see W)
[[ function start ][ function end
[{ block start ]} block end
[] pre function ]] next function
[# pre #ifdef ]# next #ifdef
[* [/ /* ]* ]/ */
[I find identifiers
ga show ascii code in cursor g8 show UTF-8 in cursor
=a{ format block of {}
== format current line
quickfix command 是vim用來控制儲存make grep命令輸出的list
:cope[n] [height] 開new window show quickfix list [height] = windwo height :ccl[ose] Close quickfix window. :cn next quickfix item :cp pre quickfix item
Note
和a] a[ i] i[一樣的有 a( a) i( i) a<> i<> a{ a}....
還有" ' 的版本 a" a' a i" i` i'
用在html或是xml的tag
at it
Note
word : [0-9a-zA-Z]組成的string Word:[^s]組成的string
和visual select很類似