Chinaunix首页 | 论坛 | 博客
  • 博客访问: 825937
  • 博文数量: 91
  • 博客积分: 2544
  • 博客等级: 少校
  • 技术积分: 1885
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-12 09:08
文章存档

2016年(10)

2014年(2)

2013年(4)

2012年(23)

2011年(23)

2010年(13)

2009年(14)

2007年(2)

分类: LINUX

2010-03-17 08:58:52


用vim cs ctags 管理项目


1,添加自己的插件函数

(1)在/home/username/下建立一个文件夹 .vim/plugins 或 .vim/plugin
(2)添加两个文件

文件1
cat cs_search_string.vim

"cs search word
func CS_Search_Word()
    let w = expand("")
    exe "cs f s" w
    exe "copen"
endfunc

" find the define
func CS_Search_define()
    let w = expand("")
    exe "cs f g" w
    exe "copen"
endfunc

" find call what funcs 
func CS_Search_whatfunc()
    let w = expand("")
    exe "cs f d" w
endfunc

" find called func
func CS_Search_calledfunc()
    let w = expand("")
    exe "cs f c" w
endfunc


" find where file the func is
func CS_Search_funcfiles()
    let w = expand("")
    exe "cs f i" w
endfunc

文件2
cat search_word.vim

"search word
func Search_Word()
    let w = expand("")
    exe "vimgrep" w "./**/*.c ./**/*.h"
    exe "copen"
endfunc

(3)在自己的home目录下,建立自己的.vimrc
内容如下:


击(此处)折叠或打开

set nu
set tabstop=4
set et
set fo-=r
set noautoindent
syntax on
map ]
map c
map
imap zz
set sw=4
"map :s/$/\=   strftime("    %Y-%m-%d %H:%M:%S")
map :s/$/\=   strftime(" %Y-%m-%d")
map :call Search_Word()
map < :cprevious
map > :cnext
map :call CS_Search_Word()
map :cclose
 
if has("cscope")
        set csprg=/usr/bin/cscope
        set csto=0
        set cst
        set nocsverb
        " add any database in current directory
        if filereadable("./cscope.out")
            cs add ./cscope.out
        " else add database pointed to by environment
        elseif $CSCOPE_DB != ""
        "if $CSCOPE_DB != ""
            cs add $CSCOPE_DB
        endif
        set csverb
endif


set cscopequickfix=e-,i-,s-,t-
map :call CS_Search_calledfunc()
map :call CS_Search_whatfunc()
hi Comment ctermfg=6


(4) 建立索引文件

#!/bin/bash
#
# ctcs

star()
{
    ctags -R *  
    if [ $? -eq 0 ]; then
        echo "ctags successfully!"
    fi 
    cscope -qbR
    if [ $? -eq 0 ]; then
        echo "cscope successfully!"
    fi 
}

del()
{
    if [ -f tags -o -f cscope.out -o -f cscope.po.out -o -f cscope.in.out ]; then
        rm -f tags  && echo "clean tags ok!"
        rm -f cscope.* && echo "clean cscope.* files ok!"
    fi 
}

case "$1" in
    -r)
        del
        star
        ;; 
    -d)
        del
        ;; 
    *) 
        echo "usage : ctcs -r|-d"  
        exit 1
esac

exit 0


阅读(1780) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~