vim+ctags+cscope+…

2019/05/0811:50:15vim+ctags+cscope+…已关闭评论

0x01 时间紧迫,赶紧上车!

CentOS 7 64位系统,二话不说,操起键盘就是干!

yum install git -y
mkdir -p ~/.vim/bundle
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

0x02 上配置!

改~/.vimrc文件

 " ----------------------------- Vundle Start -----------------------------
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'The-NERD-tree'
Bundle 'tamlok/vim-markdown'
Plugin 'jiangmiao/auto-pairs'

Plugin 'Valloric/YouCompleteMe'

call vundle#end()
filetype plugin indent on
" ----------------------------- Vundle End   -----------------------------


syntax on
set hlsearch
colorscheme desert
set nocompatible
set backspace=indent,eol,start
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4


let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"'}
"let g:AutoPairs['<']='>'
"let b:AutoPairs = g:AutoParis

set viminfo='10,\"100,:20,%,n~/.viminfo 

au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("")|exe("norm '\"")|else|exe "norm"|endif|endif


map <F11> i<C-R>=strftime("Date:%Y-%m-%d %H:%M:%S")<CR><Esc>
"map <F11> <Esc>:DoxAuthor<cr>
" 函数加注释快捷键
map <F12> <Esc>:Dox<cr>


func SetComment()
call setline(1,"/**************************************************************")
call append(line("."),   "*     Copyright (C) 2006-".strftime("%Y")." All rights reserved.")
call append(2,"*       @Version: 1.0")
call append(3,"*       @Created: " . strftime("%Y-%m-%d %H:%M"))
call append(4,"*        @Author: guozi - guozi@guoziweb.com")
call append(5,"*   @Description: ")
call append(6,"*")
call append(7,"*       @History: ")
call append(8,"**************************************************************/")
endfunc
autocmd BufNewFile *.c,*.cpp,*.php exec ":call SetComment()"


" ====================Ycm configurations begin============================
" 
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples'
let g:ycm_server_python_interpreter='/usr/bin/python2.7'

"检测文件类型
filetype on
"针对不同的文件采取不同的缩进方式
filetype indent on
"允许插件
filetype plugin on
"启动智能补全
filetype plugin indent on
" 自动补全配置
"让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)
set completeopt=longest,menu    
"离开插入模式后自动关闭预览窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif 
"回车即选中当前项
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"    
" 从第2个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=2     
" 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0      
" 语法关键字补全
let g:ycm_seed_identifiers_with_syntax=1        
" 在注释输入中也能补全
let g:ycm_complete_in_comments = 1
"在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
"注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0
nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> 
" 跳转到定义处
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
inoremap { {}<ESC>i
inoremap < <><ESC>i
set encoding=utf-8
" ======================Ycm configurations end===============================


if has("cscope")    
        set csprg=/usr/bin/cscope    
    "add any database in current dir  
    if filereadable("cscope.out")  
        cs add cscope.out  
    "else search cscope.out elsewhere  
    else  
        let cscope_file=findfile("cscope.out", ".;")  
        let cscope_pre=matchstr(cscope_file, ".*/")  
        if !empty(cscope_file) && filereadable(cscope_file)  
            exe "cs add" cscope_file cscope_pre  
        endif        
    endif    
endif    

nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>  
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR> 
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>  
nmap <C-@>s :cs find s <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> 

0x03 上插件!

在vim命令行模式下输入

:PluginInstall

All done!

  • 微信扫码赞助
  • weinxin
  • 支付宝赞助
  • weinxin
  • A+
所属分类:VIM