2014年6月17日 星期二

記錄一下自己vim的hotkey

Tabs相關

  • 產生新tab:<Ctrl-T><Ctrl-T>
  • 關掉目前的tab:<Ctrl-T><Ctrl-W>
  • 移到前ㄧ個tab:<Shift-H>
  • 移到下ㄧ個tab:<Shift-L>

Split(分割視窗)相關

  • 移到左split:<Ctrl-w>H
  • 移到右split:<Ctrl-w>L
  • 移到上split:<Ctrl-w>K
  • 移到下split:<Ctrl-w>J

開啓/關閉NERDTree:<Fn><F6>

開啓/關閉TagBar:<Fn><F7>

ctags

  • 搜尋游標所在變數、函式定義:<Ctrl-w>]
  • 回到搜尋處:<Ctrl-w>t

cscope

  • <Fn>s   symbol: find all references to the token under cursor
  • <Fn>g   global: find global definition(s) of the token under cursor
  • <Fn>c   calls:  find all calls to the function name under cursor
  • <Fn>t   text:   find all instances of the text under cursor
  • <Fn>e   egrep:  egrep search for the word under cursor
  • <Fn>f   file:   open the filename under cursor
  • <Fn>i   includes: find files that include the filename under cursor
  • <Fn>d   called: find functions that function under cursor calls

script to generate cscope and ctags files

因為工作需要,所以寫了一個簡單的shell script來幫忙產生新的ctags以及cscope檔案



# put this script to the top directory of source code
CSCOPE_PATH=`pwd`
CTAGS_PATH=`pwd`
# remove cscope files
echo "remove cscpoe.out"
if [ -f $CSCOPE_PATH/cscope.out ]; then
    rm cscope.out
fi
echo "remove cscpoe.in.out"
if [ -f $CSCOPE_PATH/cscope.in.out ]; then
    rm cscope.in.out
fi
echo "remove cscpoe.po.out"
if [ -f $CSCOPE_PATH/cscope.po.out ]; then
    rm cscope.po.out
fi
# remove ctags files
echo "remove tags"
if [ -f $CTAGS_PATH/tags ]; then
    rm tags
fi
# recreate cscpoe files
cscope -Rbkq
ctags -R
# use the following script instead of 'cscpoe -Rbkq' to add .cc into cscope
#find . -name "*.h" -o -name "*.c"-o -name "*.cc" > cscope.files
#cscope -bkq -i cscope.files

其實用for loop來寫比較簡潔,不過這樣寫比較容易懂,所以算了 XD

另外好像應該找一個可以模擬script的css來用比較好讀