vim配置 C/C++开发环境

[root@localhost ~]# cat installvim8.sh 
#!/bin/sh
git clone https://github.com/vim/vim.git
cd vim/src
./configure --enable-pythoninterp=yes --enable-python3interp=yes
make
sudo make installvim
[root@localhost ~]# cat install_vundle.sh
#!/bin/sh
mkdir -p ~/.vim/bundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
[root@localhost ~]# 

set nocompatible              " 去除VI一致性,必须要添加
filetype off                  " 必须要添加

" 设置包括vundle和初始化相关的runtime path
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" 另一种选择, 指定一个vundle安装插件的路径
"call vundle#begin('~/some/path/here')

" 让vundle管理插件版本,必须
Plugin 'VundleVim/Vundle.vim'

" 请将安装插件的命令放在vundle#begin和vundle#end之间.
"Plugin 'tpope/vim-fugitive'
" 正确指定路径用以设置runtimepath. 以下范例插件在sparkup/vim目录下
"Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" 安装L9,如果已经安装过这个插件,可利用以下格式避免命名冲突
"Plugin 'ascenator/L9', {'name': 'newL9'}
Plugin 'L9'
Plugin 'scrooloose/nerdtree'
Bundle 'altercation/vim-colors-solarized'
Plugin 'vim-scripts/OmniCppComplete'
Plugin 'Valloric/YouCompleteMe'
Plugin 'chxuan/cpp-mode'
Plugin 'vim-scripts/ctags.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'DoxygenToolkit.vim'
Plugin 'taglist.vim'
Plugin 'scrooloose/nerdcommenter'

" 你的所有插件需要在下面这行之前
call vundle#end()            " 必须
filetype plugin indent on    " 必须 加载vim自带和插件相应的语法和文件类型相关脚本
" 忽视插件改变缩进,可以使用以下替代:
"filetype plugin on

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
set nobackup
set diffexpr=MyDiff()
function MyDiff()
        let opt = '-a --binary '
        if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
        if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
        let arg1 = v:fname_in
        if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
        let arg2 = v:fname_new
        if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
        let arg3 = v:fname_out
        if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
        let eq = ''
        if $VIMRUNTIME =~ ' '
                if &sh =~ '\                         let cmd = '""' . $VIMRUNTIME . '\diff"'
                        let eq = '"'
                else
                        let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
                endif
        else
                let cmd = $VIMRUNTIME . '\diff'
        endif
        silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"显示行号
set nu!
colorscheme desert 
syntax enable 
syntax on

set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
        set fileencoding=chinese
else
        set fileencoding=utf-8
endif
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解决consle输出乱码
language messages zh_CN.utf-8

set nu "显示行号
set showcmd "显示输入命令
set tabstop=4 "设置tab键缩进
set autoindent "设置自动缩进
set cindent "c/c++缩进
set clipboard+=unnamed "共享剪切板
set mouse=a "设置鼠标可用

" 关闭NERDTree快捷键
" map t :NERDTreeToggle
map :NERDTreeToggle
" 显示行号
let NERDTreeShowLineNumbers=1
let NERDTreeAutoCenter=1
" 是否显示隐藏文件
let NERDTreeShowHidden=0
" 设置宽度
let NERDTreeWinSize=30
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1
" 忽略一下文件的显示
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
" 显示书签列表
let NERDTreeShowBookmarks=1
" vim不指定具体文件打开是,自动使用nerdtree
" autocmd StdinReadPre * let s:std_in=1
" autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

" 当vim打开一个目录时,nerdtree自动使用
" autocmd StdinReadPre * let s:std_in=1
" autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif
" 当vim中没有其他文件,值剩下nerdtree的时候,自动关闭窗口
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" 改变nerdtree的箭头
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'

let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
"cpp-mode
nnoremap y :CopyCode
nnoremap p :PasteCode
nnoremap U :GoToFunImpl
nnoremap a :Switch
nnoremap fp :FormatFunParam
nnoremap if :FormatIf

""""""""""""""""""""""""""
" Doxygen license comment
""""""""""""""""""""""""""
let g:DoxygenToolkit_briefTag_pre = "@brief\t"
let g:DoxygenToolkit_briefTag_funcName = "yes"
let g:DoxygenToolkit_briefTag_post = ""
let g:DoxygenToolkit_templateParamTag_pre = "@tparam\t"
let g:DoxygenToolkit_paramTag_pre = "@param\tstring\t"
let g:DoxygenToolkit_returnTag = "@return\t"
let g:DoxygenToolkit_throwTag_pre = "@throw\t"
let g:DoxygenToolkit_fileTag = "@script\t"
let g:DoxygenToolkit_dateTag = "@modify\t"
let g:DoxygenToolkit_authorTag = "@author\t"
let g:DoxygenToolkit_versionTag = "@version\t"
let g:DoxygenToolkit_versionString = "1.0.0"
let g:DoxygenToolkit_blockTag = "@name\t"
let g:DoxygenToolkit_classTag = "@class\t"
let g:DoxygenToolkit_authorName = "G.F "
let g:doxygen_enhanced_color = 1
let g:DoxygenToolkit_blockHeader="*******************************************************" 
let g:DoxygenToolkit_blockFooter="*******************************************************" 

let s:licenseTag = "\
let s:licenseTag = s:licenseTag . "Call Center On Demand Product Series\
let s:licenseTag = s:licenseTag . "Copyright (C/C++) 2019 G.F Soft(Beijing.) Technology Ltd., Co.\
let s:licenseTag = s:licenseTag . "All right reserved\
let g:DoxygenToolkit_licenseTag = s:licenseTag 

nmap dxa :DoxAuthor
nmap dx :Dox
nmap dxl :DoxLic
nmap dxb :DoxBlock

"--ctags setting--
" 按下F5重新生成tag文件,并更新taglist
map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . :TlistUpdate
imap :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q . :TlistUpdate
set tags=tags
set tags+=./tags "add current directory's generated tags file
set tags+=~/arm/linux-2.6.24.7/tags "add new tags file(刚刚生成tags的路径,在ctags -R 生成tags文件后,不要将tags移动到别的目录,否则ctrl+]时,会提示找不到源码文件)

set tags+=./tags表示在当前工作目录下搜索tags文件
"-- Taglist setting --
map :TlistToggle
let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行
let Tlist_Use_Right_Window=1 "让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表
let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
"是否一直处理tags.1:处理;0:不处理
let Tlist_Process_File_Always=1 "实时更新tags
let Tlist_Inc_Winwidth=0

" add header comments for .h .c .hpp .cpp .mk .sh new file
" auto call SetTitle func
autocmd BufNewFile *.[ch],*.hpp,*.cpp,Makefile,*.mk,*.sh,*.py exec ":call SetTitle()"
 
" add comment for cpp
func SetComment_ch()
    call setline(1,"/*================================================================")
    call append(line("."),   "*   Copyright (C) ".strftime("%Y")." * Ltd. All rights reserved.")
    call append(line(".")+1, "*   ")
    call append(line(".")+2, "*   File name   : ".expand("%:t"))
    call append(line(".")+3, "*   Author      : G.F")
    call append(line(".")+4, "*   Email       : [email protected]")
    call append(line(".")+5, "*   Created date: ".strftime("%F %T"))
    call append(line(".")+6, "*   Description : ")
    call append(line(".")+7, "*")
    call append(line(".")+8, "*===============================================================*/")
    call append(line(".")+9, "")
    call append(line(".")+10, "")
endfunc
" add comment for shell,Makefile
func SetComment_sh()
    call setline(3, "#================================================================")
    call setline(4, "#   Copyright (C) ".strftime("%Y")." * Ltd. All rights reserved.")
    call setline(5, "#   ")
    call setline(6, "#   File name   : ".expand("%:t"))
    call setline(7, "#   Author      : longbin")
    call setline(8, "#   Email       : [email protected]")
    call setline(9, "#   Created date: ".strftime("%F %T"))
    call setline(10, "#   Description : ")
    call setline(11, "#")
    call setline(12, "#================================================================")
    call setline(13, "")
    call setline(14, "")
endfunc
 
" SetTitle func, add comment
func SetTitle()
    if &filetype == 'make'
        call setline(1,"")
        call setline(2,"")
        call SetComment_sh()
    elseif &filetype == 'sh'
        call setline(1,"#! /bin/bash")
        call setline(2,"")
        call SetComment_sh()
 
    elseif &filetype == 'python'
        call setline(1,"#! /usr/bin/env python")
        call setline(2,"# coding=utf-8")
        call setline(3,"")
        call SetComment_sh()
 
    else
        call SetComment_ch()
        if expand("%:e") == 'hpp'
            call append(line(".")+10, "#ifndef _".toupper(expand("%:t:r"))."_H")
            call append(line(".")+11, "#define _".toupper(expand("%:t:r"))."_H")
            call append(line(".")+12, "#ifdef __cplusplus")
            call append(line(".")+13, "extern \"C\"")
            call append(line(".")+14, "{")
            call append(line(".")+15, "#endif")
            call append(line(".")+16, "")
            call append(line(".")+17, "#ifdef __cplusplus")
            call append(line(".")+18, "}")
            call append(line(".")+19, "#endif")
            call append(line(".")+20, "#endif //".toupper(expand("%:t:r"))."_H")
 
        elseif expand("%:e") == 'h'
            call append(line(".")+10, "#pragma once")
 
        elseif &filetype == 'c'
            call append(line(".")+10,"#include \"".expand("%:t:r").".h\"")
 
        elseif &filetype == 'cpp'
            call append(line(".")+10, "#include \"".expand("%:t:r").".h\"")
 
        endif
 
    endif
endfunc

inoremap ( ()i
inoremap [ []i
"inoremap < <>i
inoremap ' ''i
inoremap " ""i
inoremap { {}oi

你可能感兴趣的:(vim配置 C/C++开发环境)