vim: 搭建vim看代码的环境

 使用 vim + ctags + cscope + taglist 阅读源码  http://my.oschina.net/u/554995/blog/59927

 vim tab变空格 http://www.cnblogs.com/hydah/archive/2012/04/10/2440225.html

 

下载安装vim
  yum search vim
  yum install vim-enhanced.x86_64

ctags 插件
    yum -y  install ctags
   
taglist插件
    wget http://jaist.dl.sourceforge.net/project/vim-taglist/vim-taglist/4.6/taglist_46.zip
    unzip taglist_46.zip;
    mkdir -p ~/.vim/plugin ; cp -r plugin/taglist.vim  ~/.vim/plugin;  
    mkdir -p  ~/.vim/doc ;  cp -r doc/taglist.txt  ~/.vim/doc;
    
cscope插件
    yum -y install cscope
   
修改vim配置文件: vi  ~/.vimrc

"       vim
let &termencoding=&encoding
set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936
filetype plugin indent on
:set nonu
set laststatus=2 "总是在最后一行显示当前编辑的文件名


"       ctags
set tags=tags;
"set autochdir


"       cscope
if filereadable("cscope.out")
    cs add cscope.out
endif

if has("cscope")
        set cscopetag   " 使支持用 Ctrl+]  和 Ctrl+t 快捷键在代码间跳来跳去
        " check cscope for definition of a symbol before checking ctags:
        " set to 1 if you want the reverse search order.
        set csto=1

        " 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

        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>
endif

"       taglist
" 按F8按钮,在窗口的左侧出现taglist的窗口,像vc的左侧的workpace
nnoremap <silent> <F8> :TlistToggle<CR><CR>
" :Tlist              调用TagList
let Tlist_Show_One_File=0                    " 只显示当前文件的tags
let Tlist_Exit_OnlyWindow=1                  " 如果Taglist窗口是最后一个窗口则退出Vim
let Tlist_Use_Right_Window=1                 " 在右侧窗口中显示
let Tlist_File_Fold_Auto_Close=1             " 自动折叠

 

====================================================================================================================

关于vim显示行号,有时候需要行号,有时候特别是需要复制的时候又太碍眼:

set nu 或者 set number //显示行号;

set nonu 或者 set nonumber //关闭自动显示行号;

set ic //查找时忽略大小写;

set noic //查找时不忽略大小写。

 

使用taglist

使用“ctrl w w”将光标调到taglist的窗口里

linux下阅读源代码的工具  http://blog.csdn.net/nancygreen/article/details/5755190

常用命令列表:

        1.  $ ctags –R *      ($ 为Linux系统Shell提示符)

        2.  $ vi –t tag         (请把tag替换为您欲查找的变量或函数名)

        3. :ts                                (ts 助记字:tags list, “:”开头的命令为VI中命令行模式命令)
        4. :tp                                (tp 助记字:tags preview)
        5. :tn                                (tn 助记字:tags next)
        6. Ctrl + ]
        7. Ctrl + T
把光标移到变量名或函数名上,然后按下“Ctrl+]”,这样就能直接跳到这个变量或函数定义的源文件中,并把光标定位到这一行。用“Ctrl+t”可以退回原来的地方。即使用户使用了N次“Ctrl+]”查找了N个变量,按N次“Ctrl+t”也能回到最初打开的文件,它会按原路返回 。

注意:运行vim的时候,必须在“tags”文件所在的目录下运行。否则,运行vim的时候还要用“:settags=”命令设定“tags”文件的路径,这样vim才能找到“tags”文件。

在完成编码时,可以手工删掉tags文件(帚把不到,灰尘不会自己跑掉^_^)。

 

====================================================================================================================

CentOS下安装VIM    http://www.centoscn.com/image-text/install/2014/0830/3612.html

几个命令:

yum search vim
which vim
yum install vim-enhanced

 

可能有用的操作:


  下载 xclip :{
        1. How To Fetch Red Hat Enterprise Linux / CentOS Linux Enable EPEL (Extra Packages for Enterprise Linux) Repository  http://www.cyberciti.biz/faq/rhel-fedora-centos-linux-enable-epel-repo/
            yum install epel-release.noarch
            
        2. yum -y install xclip
    }
    
 下载安装astyle:
    tar -zxvf astyle_2.05.1_linux.tar.gz
    cd astyle/build/gcc/ && make
    make install
    # astyle -V
        Artistic Style Version 2.05.1

 

posted @ 2015-12-02 17:16  oucaijun  阅读(1116)  评论(0编辑  收藏  举报
下载TeamViewer完整版 下载TeamViewer