LNX=$PWD
echo "generate cscope index files..."
cd $LNX
find $LNX \
-path "$LNX/arch/*" ! -path "$LNX/arch/arm*" -prune -o \
-path "$LNX/arch/arm/mach-*" ! -path "$LNX/arch/arm/mach-pxa*" \
! -path "$LNX/arch/arm/mach-mmp*" \
! -path "$LNX/arch/arm/mach-tegra*" -prune -o \
-path "$LNX/arch/arm/plat-*" ! -path "$LNX/arch/arm/plat-pxa*" -prune -o \
-path "$LNX/include/asm-*" ! -path "$LNX/include/asm-arm*" \
! -path "$LNX/include/asm-generic*" -prune -o \
-path "$LNX/tmp*" -prune -o \
-path "$LNX/Documentation*" -prune -o \
-path "$LNX/scripts*" -prune -o \
-path "$LNX/patches*" -prune -o \
-path "$LNX/drivers/*" ! -path "$LNX/drivers/base*" \
! -path "$LNX/drivers/char*" \
! -path "$LNX/drivers/usb*" \
! -path "$LNX/drivers/regulator*" \
! -path "$LNX/drivers/mmc*" \
! -path "$LNX/drivers/i2c*" \
! -path "$LNX/drivers/power*" \
! -path "$LNX/drivers/mspm_dyn*" \
! -path "$LNX/drivers/gpio*" \
! -path "$LNX/drivers/video*" \
! -path "$LNX/drivers/tty*" \
! -path "$LNX/drivers/serial*" \
! -path "$LNX/drivers/rtc*" \
! -path "$LNX/drivers/switch*" \
! -path "$LNX/drivers/cpufreq*" \
! -path "$LNX/drivers/cpuidle*" \
! -path "$LNX/drivers/mfd*" -prune -o \
-name "*.[chxsS]" -print > $LNX/cscope.files
cscope -b -q -k
find ./ \( -path './dir0*' -o -path './dir1*' \) -a -name *.txt -print
-b: 只生成索引文件,不进入cscope的界面
-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
-k: 在生成索引文件时,不搜索/usr/include目录
-i: 如果保存文件列表的文件名不是cscope.files时,需要加此选项告诉cscope到哪儿去找源文件列表。可以使用“-”,表示由标准输入获得文件列表。
- Ctrl+]将跳到光标所在变量或函数的定义处 Ctrl+T返回
- :cs find s ---- 查找C语言符号,即查找函数名、宏、枚举值等出现的地方
:cs find g ---- 查找函数、宏、枚举等定义的位置,类似ctags所提供的功能
:cs find d ---- 查找本函数调用的函数
:cs find c ---- 查找调用本函数的函数
:cs find t: ---- 查找指定的字符串
:cs find e ---- 查找egrep模式,相当于egrep功能,但查找速度快多了
:cs find f ---- 查找并打开文件,类似vim的find功能
:cs find i ---- 查找包含本文件的文 - 2的所以命令也可以且按銉来实现:
-
- Ctrl+\ 再按 s 表示:cs find s命令
- 同理实现cs find + g,d,c,t,e,f,i命令
如果需要自动map快捷键,则需要在.vimrc中加入如下脚本代码:
Download VIM's cscope plugin file: ;
Save the cscope_maps.vim file into folder: /usr/share/vim/vim73/plugin/ or ~/.vim/plugin;
而且如果你打开了 set cscopetag 选项,你就不再需要ctags了,原来的ctrl+J就变成和ctags一样的ctrl+],ctrl+t不变,vim -t 也可以用。
set hlsearch
set incsearch
set smartindent
set autoindent
let Tlist_Ctags_Cmd = "/usr/bin/ctags --language-force=C"
let Tlist_Inc_Winwidth = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Process_File_Always = 1
let Tlist_Enable_Fold_Column = 0
let Tlist_Show_One_File = 1
"let tlist_php_settings = 'php;c:class;d:constant;f:function'
nnoremap
if has("cscope")
""""""""""""" Standard cscope/vim boilerplate
" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
set cscopetag
" check cscope for definition of a symbol before checking ctags: set to 1
" if you want the reverse search order.
set csto=0
" add any cscope database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add the database pointed to by environment variable
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
" show msg when any other cscope db added
set cscopeverbose
""""""""""""" My cscope/vim key mappings
"
" The following maps all invoke one of the following cscope search types:
"
" 's' symbol: find all references to the token under cursor
" 'g' global: find global definition(s) of the token under cursor
" 'c' calls: find all calls to the function name under cursor
" 't' text: find all instances of the text under cursor
" 'e' egrep: egrep search for the word under cursor
" 'f' file: open the filename under cursor
" 'i' includes: find files that include the filename under cursor
" 'd' called: find functions that function under cursor calls
"
" Below are three sets of the maps: one set that just jumps to your
" search result, one that splits the existing vim window horizontally and
" diplays your search result in the new window, and one that does the same
" thing, but does a vertical split instead (vim 6 only).
"
" I've used CTRL-\ and CTRL-@ as the starting keys for these maps, as it's
" unlikely that you need their default mappings (CTRL-\'s default use is
" as part of CTRL-\ CTRL-N typemap, which basically just does the same
" thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
" If you don't like using or CTRL-\, , you can change some or all
" of these maps to use other keys. One likely candidate is 'CTRL-_'
" (which also maps to CTRL-/, which is easier to type). By default it is
" used to switch between Hebrew and English keyboard mode.
"
" All of the maps involving the
" that searches over '#include
" 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
" files that contain 'time.h' as part of their name).
" To do the first type of search, hit 'CTRL-\', followed by one of the
" cscope search types above (s,g,c,t,e,f,i,d). The result of your cscope
" search will be displayed in the current window. You can use CTRL-T to
" go back to where you were before the search.
"
nmap
nmap
nmap
nmap
nmap
nmap
nmap
nmap
" Using 'CTRL-spacebar' (intepreted as CTRL-@ by vim) then a search type
" makes the vim window split horizontally, with search result displayed in
" the new window.
"
" (Note: earlier versions of vim may not have the :scs command, but it
" can be simulated roughly via:
" nmap <C-@>s<>
nmap <C-@>s<> :scs find s
nmap <C-@>g<> :scs find g
nmap <C-@>c<> :scs find c
nmap <C-@>t<> :scs find t
nmap <C-@>e<> :scs find e
nmap <C-@>f<> :scs find f
nmap <C-@>i<> :scs find i ^
nmap <C-@>d<> :scs find d
" Hitting CTRL-space *twice* before the search type does a vertical
" split instead of a horizontal one (vim 6 and up only)
"
" (Note: you may wish to put a 'set splitright' in your .vimrc
" if you prefer the new window on the right instead of the left
nmap <C-@>
nmap <C-@>
nmap <C-@>
nmap <C-@>
nmap <C-@>
nmap <C-@>
nmap <C-@>
nmap <C-@>
""""""""""""" key map timeouts
"
" By default Vim will only wait 1 second for each keystroke in a mapping.
" You may find that too short with the above typemaps. If so, you should
" either turn off mapping timeouts via 'notimeout'.
"
"set notimeout
"
" Or, you can keep timeouts, by uncommenting the timeoutlen line below,
" with your own personal favorite value (in milliseconds):
"
"set timeoutlen=4000
"
" Either way, since mapping timeout settings by default also set the
" timeouts for multicharacter 'keys codes' (like
" set ttimeout and ttimeoutlen: otherwise, you will experience strange
" delays as vim waits for a keystroke after you hit ESC (it will be
" waiting to see if the ESC is actually part of a key code like
"
"set ttimeout
"
" personally, I find a tenth of a second to work well for key code
" timeouts. If you experience problems and have a slow terminal or network
" connection, set it higher. If you don't set ttimeoutlen, the value for
" timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
"
"set ttimeoutlen=100
endif