FreeBsd6.1搭建vim6.4 + ctags5.5.4 + cscope15.5

   

        开始我的unix平台开发艰苦之旅。


        在unix下,因为我想尽量少用GUI,于是吃着c/c++的老本,拖着在windowns下开发的疲惫的身躯,进入了unix

开发。因为少了windowns下强大的IDE的支持,才发现每次代码里对一个系统函数或者C库函数的调用,都不知道

该如何去查找它的函数原型,更不要说代码智能匹配了,只能是用最笨的法子,先cd然后ls,最后vim一番,

效率非常之低下。。。崩溃中了。

        在google上搜索了一番,发现很多在unix下开发使用vim/emac+ctags/cscope+taglist,我于是也花了我整整半

天的时间搭建了我自己的unix开发平台。其中走了不少弯路,花了不少时间,为了以后有类似的人少浪费时间,和

避免以后遗忘,就将我的搭建过程写到csdn里(现在这次已经是第二次写了,因为该死的csdn居然不写tag的话就

提交不了文章,而我当时又没有保存,然后出错回退之后就是所有的东西都清空了,csdn的BLOG太令人失望了)

 


 

一、平台。

FreeBsd6.1

系统默认安装了:

(1)vim6.4

(2)ctags5.5.4

(3)cscope15.5

 


 

二、工具安装。


1、taglist_42


(1)下载taglist_42.zip


http://nchc.dl.sourceforge.net/sourceforge/vim-taglist/taglist_42.zip

(2)安装


taglist作为vim的插件安装。


1)解压taglist_42.zip


2)将taglist.txt复制到


/usr/local/share/vim/vim64/doc/下


3)将taglist.vim复制到


/usr/local/share/vim/vim64/plugin/下

2、ctags5.5.4

(1)下载ctags5.5.4

http://nchc.dl.sourceforge.net/sourceforge/ctags/ctags-5.5.4.tar.gz

因为FreeBsd6.1默认安装的ctags没有安装exctags,在vim里使用:Tlist的时候要使用exctags,不然报错如下:

Taglist: Failed to generate tags for /root/wrapstdio.c
ctags: illegal option -- -^@usage: ctags [-BFTaduwvx] [-f tagsfile] file ...^@

所以要重新安装。

(2)安装ctags5.5.4

1)复制ctags5.5.4到/usr/ports/distfiles/

 

#   cd   / usr / ports / devel / ctags /


#  make install clean 

 

2)编辑$HOME/.vimrc,增加:

 

let Tlist_Ctags_Cmd  =   " /usr/local/bin/exctags "

 

用vim编辑.c文件,然后输入:Tlist就会在左边显示函数列表,宏定义,结构体等信息。

 


 

三、cscope的使用

1、配置。

1)下载配置文件cscope.vim


http://cscope.sourceforge.net/cscope_maps.vim

2)编辑$HOME/.vimrc,增加:


source ~ / cscope . vim

 

2、命令使用


   cscope -Rbkq

 


这个命令会生成三个文件:cscope.out, cscope.in.out, cscope.po.out。


其中cscope.out是基本的符号索引,后两个文件是使用"-q"选项生成的,可以加快cscope的索引速度。


上面所用到的命令参数,含义如下:

-R: 在生成索引文件时,搜索子目录树中的代码


-b: 只生成索引文件,不进入cscope的界面


-k: 在生成索引文件时,不搜索/usr/include目录


-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度

接下来,就可以在vim里读代码了。


不过在使用过程中,发现无法找到C++的类、函数定义、调用关系。仔细阅读了cscope的手册后发现,原来

cscope在产生索引文件时,只搜索类型为 C, lex和yacc的文件(后缀名为.c, .h, .l, .y),C++的文件根本没有生成索

引。不过按照手册上的说明,cscope支持c++和Java语言的文件。

于是按照cscope手册上提供的方法,先产生一个文件列表,然后让cscope为这个列表中的每个文件都生成索引。

为了方便使用,编写了下面的脚本来更新cscope和ctags的索引文件:

 

# ! / bin / sh

find   .  -name  " *.h "  -o -name  " *.c "  -o -name  " *.cc "   >  cscope . files


cscope -bkq -i cscope
. files


/ usr / local / bin / exctags -R

 

3、实例。索引/目录下的所有.h,.c文件

(1)在$HOME目录下,我的机器为/root


运行


cscope -Rbkq -s  /

 


在/root目录下生成三个文件cscope.in.out   cscope.out      cscope.po.out


(2)修改cscope.vim文件,见附录。


主要是修改41、42行,将cscope.out路径写为绝对路径,那样,所有用vim编辑的文件都会查找此目录下的

cscope.out。


到此,历经辛苦终于搭建完成。

 


 


附录cscope.vim文件。
      

       1   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
      
2   "  CSCOPE settings for vim           
       3   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
      
4   "
       5   "  This file contains some boilerplate settings for vim's cscope interface,
       6   "  plus some keyboard mappings that I've found useful.
       7   "
       8   "  USAGE: 
       9   "  -- vim 6:     Stick this file in your ~/.vim/plugin directory (or in a
      10   "                'plugin' directory in some other directory that is in your
      11   "                'runtimepath'.
      12   "
      13   "  -- vim 5:     Stick this file somewhere and 'source cscope.vim' it from
      14   "                your ~/.vimrc file (or cut and paste it into your .vimrc).
      15   "
      16   "  NOTE: 
      17   "  These key maps use multiple keystrokes (2 or 3 keys).  If you find that vim
      18   "  keeps timing you out before you can complete them, try changing your timeout
      19   "  settings, as explained below.
      20   "
      21   "  Happy cscoping,
      22   "
      23   "  Jason Duell       jduell@alumni.princeton.edu     2002/3/7
      24   """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
     
25  
     
26  
     
27   "  This tests to see if vim was configured with the '--enable-cscope' option
      28   "  when it was compiled.  If it wasn't, time to recompile vim... 
      29   if  has( " cscope " )
     
30  
     
31       """""""""""""  Standard cscope/vim boilerplate
      32  
     
33       "  use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
      34      set cscopetag
     
35  
     
36       "  check cscope for definition of a symbol before checking ctags: set to 1
      37       "  if you want the reverse search order.
      38      set csto = 0
     
39  
     
40       "  add any cscope database in current directory
      41       if  filereadable( " /root/cscope.out " )
     
42          cs add  / root / cscope.out
     
43       "  else add the database pointed to by environment variable 
      44      elseif $CSCOPE_DB  !=   ""
     
45          cs add $CSCOPE_DB
     
46      endif
     
47  
     
48       "  show msg when any other cscope db added
      49      set cscopeverbose
     
50  
     
51  
     
52       """""""""""""  My cscope/vim key mappings
      53       "
      54       "  The following maps all invoke one of the following cscope search types:
      55       "
      56       "    's'   symbol: find all references to the token under cursor
      57       "    'g'   global: find global definition(s) of the token under cursor
      58       "    'c'   calls:  find all calls to the function name under cursor
      59       "    't'   text:   find all instances of the text under cursor
      60       "    'e'   egrep:  egrep search for the word under cursor
      61       "    'f'   file:   open the filename under cursor
      62       "    'i'   includes: find files that include the filename under cursor
      63       "    'd'   called: find functions that function under cursor calls
      64       "
      65       "  Below are three sets of the maps: one set that just jumps to your
      66       "  search result, one that splits the existing vim window horizontally and
      67       "  diplays your search result in the new window, and one that does the same
      68       "  thing, but does a vertical split instead (vim 6 only).
      69       "
      70       "  I've used CTRL- and CTRL-@ as the starting keys for these maps, as it's
      71       "  unlikely that you need their default mappings (CTRL-'s default use is
      72       "  as part of CTRL- CTRL-N typemap, which basically just does the same
      73       "  thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
      74       "  If you don't like using 'CTRL-@' or CTRL-, , you can change some or all
      75       "  of these maps to use other keys.  One likely candidate is 'CTRL-_'
      76       "  (which also maps to CTRL-/, which is easier to type).  By default it is
      77       "  used to switch between Hebrew and English keyboard mode.
      78       "
      79       "  All of the maps involving the <cfile> macro use '^<cfile>$': this is so
      80       "  that searches over '#include <time.h> "   return  only references to
     
81       "  'time.h', and not 'sys/time.h', etc. (by default cscope will return all
      82       "  files that contain 'time.h' as part of their name).
      83  
     
84  
     
85       "  To do the first type of search, hit 'CTRL-', followed by one of the
      86       "  cscope search types above (s,g,c,t,e,f,i,d).  The result of your cscope
      87       "  search will be displayed in the current window.  You can use CTRL-T to
      88       "  go back to where you were before the search.  
      89       "
      90  
     
91      nmap  < C - > s :cs find s  < C - R >= expand( " <cword> " ) < CR >< CR >
     
92      nmap  < C - > g :cs find g  < C - R >= expand( " <cword> " ) < CR >< CR >
     
93      nmap  < C - > c :cs find c  < C - R >= expand( " <cword> " ) < CR >< CR >
     
94      nmap  < C - > t :cs find t  < C - R >= expand( " <cword> " ) < CR >< CR >
     
95      nmap  < C - > e :cs find e  < C - R >= expand( " <cword> " ) < CR >< CR >
     
96      nmap  < C - > f :cs find f  < C - R >= expand( " <cfile> " ) < CR >< CR >
     
97      nmap  < C - > i :cs find i  ^< C - R >= expand( " <cfile> " ) < CR > $ < CR >
     
98      nmap  < C - > d :cs find d  < C - R >= expand( " <cword> " ) < CR >< CR >
     
99  
    
100  
    
101       "  Using 'CTRL-spacebar' (intepreted as CTRL-@ by vim) then a search type
     102       "  makes the vim window split horizontally, with search result displayed in
     103       "  the new window.
     104       "
     105       "  (Note: earlier versions of vim may not have the :scs command, but it
     106       "  can be simulated roughly via:
     107       "     nmap <C-@>s <C-W><C-S> :cs find s <C-R>=expand( " < cword > " )<CR><CR>  
     108  
    
109      nmap  < C - @ > s :scs find s  < C - R >= expand( " <cword> " ) < CR >< CR >
    
110      nmap  < C - @ > g :scs find g  < C - R >= expand( " <cword> " ) < CR >< CR >
    
111      nmap  < C - @ > c :scs find c  < C - R >= expand( " <cword> " ) < CR >< CR >
    
112      nmap  < C - @ > t :scs find t  < C - R >= expand( " <cword> " ) < CR >< CR >
    
113      nmap  < C - @ > e :scs find e  < C - R >= expand( " <cword> " ) < CR >< CR >
    
114      nmap  < C - @ > f :scs find f  < C - R >= expand( " <cfile> " ) < CR >< CR >
    
115      nmap  < C - @ > i :scs find i  ^< C - R >= expand( " <cfile> " ) < CR > $ < CR >
    
116      nmap  < C - @ > d :scs find d  < C - R >= expand( " <cword> " ) < CR >< CR >
    
117  
    
118  
    
119       "  Hitting CTRL-space *twice* before the search type does a vertical 
     120       "  split instead of a horizontal one (vim 6 and up only)
     121       "
     122       "  (Note: you may wish to put a 'set splitright' in your .vimrc
     123       "  if you prefer the new window on the right instead of the left
     124  
    
125      nmap  < C - @ >< C - @ > s :vert scs find s  < C - R >= expand( " <cword> " ) < CR >< CR >
    
126      nmap  < C - @ >< C - @ > g :vert scs find g  < C - R >= expand( " <cword> " ) < CR >< CR >
    
127      nmap  < C - @ >< C - @ > c :vert scs find c  < C - R >= expand( " <cword> " ) < CR >< CR >
    
128      nmap  < C - @ >< C - @ > t :vert scs find t  < C - R >= expand( " <cword> " ) < CR >< CR >
    
129      nmap  < C - @ >< C - @ > e :vert scs find e  < C - R >= expand( " <cword> " ) < CR >< CR >
    
130      nmap  < C - @ >< C - @ > f :vert scs find f  < C - R >= expand( " <cfile> " ) < CR >< CR >
    
131      nmap  < C - @ >< C - @ > i :vert scs find i  ^< C - R >= expand( " <cfile> " ) < CR > $ < CR >
    
132      nmap  < C - @ >< C - @ > d :vert scs find d  < C - R >= expand( " <cword> " ) < CR >< CR >
    
133  
    
134  
    
135       """""""""""""  key map timeouts
     136       "
     137       "  By default Vim will only wait 1 second for each keystroke in a mapping.
     138       "  You may find that too short with the above typemaps.  If so, you should
     139       "  either turn off mapping timeouts via 'notimeout'.
     140       "
     141       " set notimeout 
     142       "
     143       "  Or, you can keep timeouts, by uncommenting the timeoutlen line below,
     144       "  with your own personal favorite value (in milliseconds):
     145       "
     146       " set timeoutlen=4000
     147       "
     148       "  Either way, since mapping timeout settings by default also set the
     149       "  timeouts for multicharacter 'keys codes' (like <F1>), you should also
     150       "  set ttimeout and ttimeoutlen: otherwise, you will experience strange
     151       "  delays as vim waits for a keystroke after you hit ESC (it will be
     152       "  waiting to see if the ESC is actually part of a key code like <F1>).
     153       "
     154       " set ttimeout 
     155       "
     156       "  personally, I find a tenth of a second to work well for key code
     157       "  timeouts. If you experience problems and have a slow terminal or network
     158       "  connection, set it higher.  If you don't set ttimeoutlen, the value for
     159       "  timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
     160       "
     161       " set ttimeoutlen=100
     162  
    
163  endif

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值