顯示具有 advance 標籤的文章。 顯示所有文章
顯示具有 advance 標籤的文章。 顯示所有文章

2015年7月14日 星期二

bookmarks, go and back

設定 bookmark, 這樣以後可以回到這裡。
設定: ma
(a,b, c....是 bookmark id)
回到... `a
(a, b, c.. 回到 bookmark a, b, c..)

2012年1月10日 星期二

ctags

跟 cscope 有點類似。
  1. 先產生 database : ctags -R
  2. 開檔,編輯
  3. 使用 ctag command
好像可以跟 cscope 一起用 (command 不衝突)
command:

到 定義: Ctrl-]
回去,跟cscope 一樣: Ctrl-T
在函数中移动光标的快捷键: [{ 转到上一个位于第一列的"{" }] 转到下一个位于第一列的"{" { 转到上一个空行 } 转到下一个空行 gd 转到当前光标所指的局部变量的定义 * 转到当前光标所指的单词下一次出现的地方 # 转到当前光标所指的单词上一次出现的地方



ref : http://blog.csdn.net/wangyunqian6/article/details/6608238

2011年10月6日 星期四

cscope : browsing codes with cscope

cscope 要先建 database,
加上 cscope for vim 的 key mapping 才能動作。

  1. 建立要cscope 處理的檔案列表
  2. 要 cscope 根據列表產生 database

cscope 會依照 cscope..files 的內容 (檔案量列表),
parsing context 產生data base。
如果是 linux kernel,
可以用 find command 找出要的 source file。

以下就是以 ARM 為例子的 shell script: #!/bin/sh find . \ -path "arch/arm/*" -prune \ -o -path "include/asm-*" \ ! -path "include/asm-i386*" -prune \ -o -path "tmp*" -prune \ -o -path "Documentation*" -prune \ -o -path "scripts*" -prune \ -o -path "drivers*" -prune \ -o -name "*.[chxsS]" -print > cscope.files 在 kernel source folder 執行完 script ,會在目錄下產生 cscope.files。


接著產生 database..

在目錄下作 cscope -b -q -k
  1. -b : 產生 database 就好,不用 launch gui
  2. -q : 產生 reverse index,方便 search
  3. -k : kernel mode , 不要對 ./usr/include 作 index


做完以上動作,cscope 的 資料就 OK 了。

下載 cscope for vim 的 keymapping 檔。
cscope_maps.vim

download 到 .vim/plugin/ 下
--- 沒有這個目錄就自己 create 一個。


之後就可以像平常一樣開啟任何一個 source file。
然後.. 在任何變數 , function 按 Ctrl \ + g 到 定義的地方。

Ctrl \ + d 列出這個 function 所有呼叫到的 function,讓你挑選。

Ctrl \ + c 到 call 這個 function 的 code 去。


要回到上一個地方用: Ctrl t
可以用 :cs help列出command.... find : Query for a pattern (Usage: find c|d|e|f|g|i|s|t name) c: Find functions calling this function d: Find functions called by this function e: Find this egrep pattern f: Find this file g: Find this definition i: Find files #including this file s: Find this C symbol t: Find assignments to
ref:
  1. http://cscope.sourceforge.net/large_projects.html
  2. http://http://forteallan.pixnet.net/blog/post/24394720-cscope-%5B%E7%80%8F%E8%A6%BD%E7%A8%8B%E5%BC%8F%E7%A2%BC%E5%B7%A5%E5%85%B7-built-with-vim%5D"
  3. http://softsmith.blogspot.com/2009/01/vim-cscope-trace.html
  4. http://adrianhuang.blogspot.com/2007/09/trace-code-gvimctagscscope.html

2011年6月21日 星期二

重新排版 - indent

重新排版功能

1. 先把要重新縮排的區域 Mark 起來
2. 啟動重新縮排

ref : 這一篇 重排所有內容

0 到行首

gg 到檔案開頭

V 進入 visual mode

G 到檔案最後 (就會 mark 到檔案最後)

= 重新縮排 mark 的區域

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年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年9月23日 星期四

browse codes using vim

安裝:

就是 follow 這一篇
  • 把 cscope.vim 放到 .vim/plugin --- 如果沒有這個 folder ,就自己 create
  • 把 goproj.sh 放到 bin -- 如果沒有這個 folder,就自己 create 一個,並且把path 加進去。
使用:
  • 到該 source folder 下,執行 goproj.sh `pwd`
  • 用 vi 開啟一個 source file
  • 移動游標到要search reference 的 function name 上,按下Ctrl 不放,再按 \ ,放掉後按 s --- 會列出所有reference 這個 function 的位置。