2011年1月12日 星期三

multiple windows

ref: http://www.cs.swarthmore.edu/help/vim/windows.html

新增一個 垂直的 windows,開啟一個檔案:
: vsplit file

水平的話就用 split。
* vsplit 可以用 vsp 代,split 可以用 sp 代

到另一個 windows (這跟用 diff 時一樣)
Ctrl-W W


關閉這個 window
: hide

好像用 :bd 也可以。


好像有一整組用 Ctrl-W 的 Windows 操作。 ref: http://selinap.com/2009/07/how-to-use-multiple-windows-in-vim/

都是以 Ctrl-W 開始:

開啟,關閉:
  • close window
  • v : split vertically
  • s : split horizontally
移動 cursor:
  • l : 移動 cursor 到右邊的 window
  • h : 移動cursor 到左邊window
  • j : 移動到上面window
  • k: 移動到下面 window
window size 調整:
  • + : windows size 增加一行 (horizontal 時有效)
  • - : windows size 減一行
  • > : 增加size (vertical 時有效)
  • < : 減少size.

2010年12月26日 星期日

Change vimdiff color


hi DiffAdd term=reverse cterm=bold ctermbg=green ctermfg=white
hi DiffChange term=reverse cterm=bold ctermbg=cyan ctermfg=black
hi DiffText term=reverse cterm=bold ctermbg=gray ctermfg=black
hi DiffDelete term=reverse cterm=bold ctermbg=red ctermfg=black


因為diff convert 的某 background C comment 的顏色一樣,所以會看不到 code,
所以改 .vimrc。
用上面的。

ref: http://kimklai.blogspot.com/

2010年11月23日 星期二

Search And Replace

簡單的 Search 是用
/String
然後用
  • N : 下一個
  • P : 上一個
如果是 Search and Replace,是用
:%s/OLD/NEW/g

* s 是小寫。

ref http://www.samtseng.liho.tw/~samtz/blog/2005/06/28/vi-search-and-replace/

一開始的 % 決定是不是整個 file 都要 replace

2010年11月14日 星期日

執行 shell command 一下下

:! 命令
好像 :! 就可以跳回 shell,所以
:! ls就可以執行 ls..

執行時,會顯示
press Enter or type command to continue..
隨便按一個鍵就可以回到 vi 剛剛編輯的畫面

2010年10月28日 星期四

remove the line ending ^M mark

DOS/Windows 的ˊ文件在 Vi 打開都會在 line ending 出現
^M

要移除。可以用 Vi 的 search and replace command:

:%s/search-word/replace-word/g

%s 命令是用 "/" 來區分,第一個 "/" 間隔是 search word,第二個 "/" 是 replace word。
尾巴的 "g" 是 Globally 的意思 (search and replace the whole document)

所以要 remove ^M 就要下:

:%s/^M//g

但是 控制字元 "^M" 在 vi 裡要分兩次input:

Control-V Control-M

這樣輸入完,就會看到 ^M

2010年10月21日 星期四

DirDiff -- compare two folders

是 vim plugin. http://www.vim.org/scripts/script.php?script_id=102

follow instruction , download 到 ~/.vim/plugin/ (如果沒有這個 folder 就自己 create)。

使用的方法是,進入 vi 後,在 command 下:
:Diff dir1 dir2
比較dir1, dir2

vi 會開啟三個 分割視窗,利用
Ctrl-W W
切換游標到各個ˊWindow

在上面的比較視窗中,可以用 vi 的 diff command 操作:
]c 下一個差異

[c 上一個差異

最下面的 Window 顯示的是 目錄比較的結果,移動游標後按 enter 可以開啟比較結果。

有關copy 的部份我:
這一個block的diff update 到 對面:
dp
用對面的來update我的這一個 block diff:
do
但是要注意,如果要undo,就要先用
Ctrl-W W
切換到 FileB之後,在用
u
undo




git 要用 vimdiff 來看 git diff 的結果,可以用:
git difftool
然後就會一個一個的把 diff 的檔用 vimdiff 打開比較。

... 如果你的 git 不是用 vimdiff 來開,可以修改 .gitconfig,加上
[diff]
tool = vimdiff





vimdiff 在顯示的時候,會把大量相同的部份fold起來(用++ 代替).
要打開的話,可以用
zR

要再折回去用:
za
如果 svn diff 要像 git diff 一樣,用 vim 來看。會比較麻煩。
ref:這一篇
大概就是要寫一個 script,讓 vim 吃 svn 的參數。

~/bin/diffwrap.sh: #!/bin/sh # Configure your favorite diff program here. DIFF="/usr/bin/vimdiff" # Subversion provides the paths we need as the sixth and seventh # parameters. LEFT=${6} RIGHT=${7} # Call the diff command (change the following line to make sense for # your merge program). $DIFF $LEFT $RIGHT # Return an errorcode of 0 if no differences were detected, 1 if some were. # Any other errorcode will be treated as fatal. 然後修改 ~/.subversion/config [helpers] diff-cmd = /home/matt/bin/diffwrap.sh

2010年10月10日 星期日

Convert Code to Html format

從這一頁看到的:Convert Code to Html in Vim

大概就是:
  • 開啟一個 edit buffer (file)
  • 把要 convert 的 code copy 過去
  • :TOhtml
這樣就 OK了。

convert 好會是整頁的 html page, white space 和 tab 都會被convert。
所以要自己選出要的部分。