syntax on
set nu
set hlsearch
set ruler
set cursorline
set ts=4
set expandtab
set ai
let Tlist_Auto_Open =1
"let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_Show_One_File = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口
map <silent> <F9> :TlistToggle<cr>
#!/bin/sh find . -name "*.h" -o -name "*.c"-o -name "*.cc" > cscope.files cscope -bkq -i cscope.files
可以在.vimrc中添加下面的快捷键,免得每次都要输入一长串命令。
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR> nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR> nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR> nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR> nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR> nmap <C-@>f :cs find f <C-R>=expand("<cword>")<CR><CR> nmap <C-@>i :cs find i ^<C-R>=expand("<cword>")<CR>$<CR> nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
使用时,将光标停留在要查找的对象上,按下<C-@>g,即先按“Ctrl+@”,然后很快再按“g”,将会查找该对象的定义。
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " cscope setting """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" if has("cscope") set csprg=/usr/bin/cscope set csto=1 set cst set nocsverb " add any database in current directory if filereadable("cscope.out") cs add cscope.out endif set csverb endif nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR> nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR> nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR> nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR> nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR> nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR> nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR> nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>
ctags
运行命令: ctags -R 其中-R表示递归遍历
然后在vim运行命令,
:
set tags=/source/tags
每次都要输入这个才能使tags生效,也可以将这句话放到~/.vimrc中去,
如果经常在不同工程间编程, 可以在.vimrc中加上:
set tags=tags;
set autochdir
使用举例:
把光标定位到某一函数名上, 按下 Ctrl + ], vim就可以自动切换到该函数定义处!
要返回只需要按下Ctrl + o 或者 Ctrl + t.
- "set ignorecase " 搜索模式里忽略大小写
- "set smartcase " 如果搜索模式包含大写字符,不使用 'ignorecase' 选项。只有在输入搜索模式并且打开 'ignorecase' 选项时才会使用。
- set autowrite " 自动把内容写回文件: 如果文件被修改过,在每个 :next、:rewind、:last、:first、:previous、:stop、:suspend、:tag、:!、:make、CTRL-] 和 CTRL-^命令时进行;用 :buffer、CTRL-O、CTRL-I、'{A-Z0-9} 或 `{A-Z0-9} 命令转到别的文件时亦然。
- set autoindent " 设置自动对齐(缩进):即每行的缩进值与上一行相等;使用 noautoindent 取消设置
- "set smartindent " 智能对齐方式
- set tabstop=4 " 设置制表符(tab键)的宽度
- set softtabstop=4 " 设置软制表符的宽度
- set shiftwidth=4 " (自动) 缩进使用的4个空格
- set cindent " 使用 C/C++ 语言的自动缩进方式
- set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s "设置C/C++语言的具体缩进方式
- "set backspace=2 " 设置退格键可用
- set showmatch " 设置匹配模式,显示匹配的括号
- set linebreak " 整词换行
- set whichwrap=b,s,<,>,[,] " 光标从行首和行末时可以跳到另一行去
- "set hidden " Hide buffers when they are abandoned
- set mouse=a " Enable mouse usage (all modes) "使用鼠标
- set number " Enable line number "显示行号
- "set previewwindow " 标识预览窗口
- set history=50 " set command history to 50 "历史记录50条
- "--状态行设置--
- set laststatus=2 " 总显示最后一个窗口的状态行;设为1则窗口数多于一个的时候显示最后一个窗口的状态行;0不显示最后一个窗口的状态行
- set ruler " 标尺,用于显示光标位置的行号和列号,逗号分隔。每个窗口都有自己的标尺。如果窗口有状态行,标尺在那里显示。否则,它显示在屏幕的最后一行上。
- "--命令行设置--
- set showcmd " 命令行显示输入的命令
- set showmode " 命令行显示vim当前模式
- "--find setting--
- set incsearch " 输入字符串就显示匹配点
- set hlsearch
CSCOPE_FILE=cscope.out if [ -n "$1" ]; then echo "Source code directory: " $1 echo "Create file map : " $CSCOPE_FILE find $1 -name "*.aidl" -o -name "*.cc" -o -name "*.h" -o -name "*.c" -o -name "*.cpp" -o -name "*.java" -o -name "*.mk" > $CSCOPE_FILE cscope -bkq -i $CSCOPE_FILE ctags -R --exclude=.svn else echo "Please key-in path of project" fi
請花點時間,試試下面幾個鍵(按下組合鍵前,移動游標到你想找的 function 上,然後再按下組合鍵)
[ Ctrl + \ + s ] : 搜尋游標上的 function 哪邊參考到
[ Ctrl + \ + c ] : 搜尋游標上的 function 哪邊呼叫到
[ Ctrl + \ + g ] : 搜尋游標上的 function 是在哪邊定義的
#!/bin/bash
#file: mkcscope
#function: make cscope database and ctags database
#author: wikijone@gmail.com
#date: 20110527
ignore="( -name .git -o -name test -o -name tests ) -prune -o"
type="( -name *.java -o -name *.cpp -o -name *.[ch] -o -name *.xml -o -name *.aidl )"
ANDROID_SRC=/work/AOSP
echo '============'
echo $ANDROID_SRC
echo '----------------------'
path="$ANDROID_SRC/frameworks \
$ANDROID_SRC/packages \
$ANDROID_SRC/external \
$ANDROID_SRC/system \
$ANDROID_SRC/bionic \
$ANDROID_SRC/hardware \
$ANDROID_SRC/dalvik \
$ANDROID_SRC/prebuilt/linux-x86 \
$ANDROID_SRC/kernel_imx \
$ANDROID_SRC/bootable"
cscopedb=$ANDROID_SRC/cscope
prepare()
{
if [ ! -d $ANDROID_SRC ]; then
echo "no ANDROID_SRC set"
echo "please set ANDROID_SRC at your .bashrc file"
exit 1
else
echo "ANDROID_SRC:$ANDROID_SRC"
if [ -d $cscopedb ]; then
echo "$cscopedb exist already"
if [ -e $cscopedb/cscope.files ]; then
echo "file $cscopedb/cscope.files exist"
# rm $cscopedb/cscope.files
fi
else
mkdir $cscopedb
echo "make directory $cscopedb"
fi
fi
all_source | sort > $cscopedb/cscope.files
lines=$(wc -l $cscopedb/cscope.files | awk '{ printf $1 }')
echo "find $lines files totaly"
}
all_source()
{
for src in $path
do
find -L $src $ignore $type -print
done
}
docscope()
{
echo "Now begin build cscope cross-index file"
start=`date +%s`
cscope -b -k -q -i $cscopedb/cscope.files -f $cscopedb/cscope.out
end=`date +%s`
let "elapse=$end-$start"
if [ $? -eq 0 ]; then
echo "make cscope database file with total time ($elapse) seconds"
size=$(du $cscopedb/cscope.out -h | awk '{ printf $1 }')
echo "($cscopedb/cscope.out):$size"
fi
}
dotags()
{
echo "Now begin build tags file"
start=`date +%s`
ctags --fields=+afiKlmnsSzt -L $cscopedb/cscope.files -f $cscopedb/tags
end=`date +%s`
let "elapse=$end-$start"
if [ $? -eq 0 ]; then
echo "make ctags database file with total time ($elapse) seconds"
size=$(du $cscopedb/tags -h | awk '{ printf $1 }')
echo "($cscopedb/tags):$size"
fi
}
usage()
{
echo "Usages:"
echo "$0 cscope : make cscope database only"
echo " tags : make ctags database only"
echo " all : make two databases"
}
case $1 in
"cscope")
prepare
docscope
;;
"tags")
prepare
dotags
;;
"all")
prepare
docscope
dotags
;;
"")
usage
;;
esac
set csto:0
set cscopetag
set nocsverb
cs add $ANDROID_SRC/cscope/cscope.out
set csverb
set tags:./tags,tags,$ANDROID_SRC/cscope/tags