我的vim

1:vim的安装 

     安装系统:ubuntu-12.04 

   apt-get install vim

     如果想使用gvim:

apt-get install vim-gtk

     或者

 apt-get install vim-gnome

2:我的vim配置文件

  

""""""""""""""""""""""""
" 基础配置
""""""""""""""""""""""""
set number "显示行号
set helplang=cn "中文帮助
colorscheme elflord "设置配色
filetype plugin indent on "打开文件类型检测
syntax on "语法高亮
set statusline+=%f "在状态栏中显示文件名
set tabstop=4 "制表符为4
set shiftwidth=4 "统一缩进为4
set autoindent "vim使用自动对齐,也就是把当前行的对起格式应用到下一行
set smartindent "依据上面的对起格式,智能的选择对起方式
set showmatch "设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号
set incsearch "在输入要搜索的文字时,vim会实时匹配
set hlsearch "高亮显示搜索的内容
"set backspace&
"set laststatus=2      " 总是显示状态栏

""""""""""""""""""""""""
" 转到工作目录
""""""""""""""""""""""""
execute ":cd /home/liangsheng/cpp/"

""""""""""""""""""""""""
" 中文编码
""""""""""""""""""""""""
"set fileencodings=gb2312,gb18030,utf-8
"set termencoding=utf-8
"set encoding=prc

""""""""""""""""""""""""
" 一键编译/运行,F5编译,F6执行,支持C/C++/Java/Python
""""""""""""""""""""""""
func! CompileGcc()
exec "w"
let compilecmd="!gcc "
let compileflag="-o %< "
if search("mpi\.h") != 0
let compilecmd = "!mpicc "
endif
if search("glut\.h") != 0
let compileflag .= " -lglut -lGLU -lGL "
endif
if search("cv\.h") != 0
let compileflag .= " -lcv -lhighgui -lcvaux "
endif
if search("omp\.h") != 0
let compileflag .= " -fopenmp "
endif
if search("math\.h") != 0
let compileflag .= " -lm "
endif
exec compilecmd." % ".compileflag
endfunc
func! CompileGpp()
exec "w"
let compilecmd="!g++ "
let compileflag="-o %< "
if search("mpi\.h") != 0
let compilecmd = "!mpic++ "
endif
if search("glut\.h") != 0
let compileflag .= " -lglut -lGLU -lGL "
endif
if search("cv\.h") != 0
let compileflag .= " -lcv -lhighgui -lcvaux "
endif
if search("omp\.h") != 0
let compileflag .= " -fopenmp "
endif
if search("math\.h") != 0
let compileflag .= " -lm "
endif
exec compilecmd." % ".compileflag
endfunc
 
func! RunPython()
exec "!python2 %"
endfunc
func! CompileJava()
exec "!javac %"
endfunc
 
 
func! CompileCode()
exec "w"
if &filetype == "cpp"
exec "call CompileGpp()"
elseif &filetype == "c"
exec "call CompileGcc()"
elseif &filetype == "python"
exec "call RunPython()"
elseif &filetype == "java"
exec "call CompileJava()"
endif
endfunc
 
func! RunResult()
exec "w"
if search("mpi\.h") != 0
exec "!mpirun -np 4 ./%<"
elseif &filetype == "cpp"
exec "! ./%<"
elseif &filetype == "c"
exec "! ./%<"
elseif &filetype == "python"
exec "call RunPython"
elseif &filetype == "java"
exec "!java %<"
endif
endfunc
 
map <F5> :call CompileCode()<CR>
imap <F5> <ESC>:call CompileCode()<CR>
vmap <F5> <ESC>:call CompileCode()<CR>
 
map <F6> :call RunResult()<CR>

""""""""""""""""""""""""
" ctags设置
""""""""""""""""""""""""
"map <F12> :!ctags -R <CR><CR> "按下F12即可生成tag
map <F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q <CR><CR> "按下F12即可生成tag
"ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
set tags=stl_tags
"set tags+=./tags	" add current directory's generated tags file
"set tags+=~/cpp/tags " add new tags file

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cscope设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <F7> :!cscope -Rb <CR><CR> "按下F7即可生成cscope.out
if has("cscope")
set csprg=/usr/bin/cscope
set csto=1
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
endif
set csverb
endif
 
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>

""""""""""""""""""""""""
" taglist设置
""""""""""""""""""""""""
map <F3> :silent! Tlist<CR> "按下F3就可以呼出了
let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,只显示当前文件的
let Tlist_Exit_OnlyWindow = 1 "当taglist是最后一个分割窗口时,自动退出vim

""""""""""""""""""""""""
" NERD_commenter的设置
""""""""""""""""""""""""
map <c-x> \c<space> "按下ctrl+c即可添加/取消注释

""""""""""""""""""""""""
"自动匹配括号
""""""""""""""""""""""""
inoremap ( ()<Esc>i
inoremap [ []<Esc>i
inoremap { {<CR>}<Esc>O
autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap } <c-r>=CloseBracket()<CR>
inoremap " <c-r>=QuoteDelim('"')<CR>
inoremap ' <c-r>=QuoteDelim("'")<CR>
 
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
 
function CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<CR>}"
else
return "\<Esc>j0f}a"
endif
endf
 
function QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - 2] == "\\"
"Inserting a quoted quotation mark into the string
return a:char
elseif line[col - 1] == a:char
"Escaping out of the string
return "\<Right>"
else
"Starting a string
return a:char.a:char."\<Esc>i"
endif
endf

" " " " " " " "
set showcmd

set lines=80 columns=82

" 与windows共享剪贴板 
set clipboard+=unnamed 

" 不要备份文件(根据自己需要取舍) 
set nobackup 

" 不要生成swap文件,当buffer被丢弃的时候隐藏它 
setlocal noswapfile 
set bufhidden=hide 

""字体大一点
set guifont=UbuntuMono\ 15

""取消高亮
map<F9> :set nohlsearch<CR>

"定义源代码格式化
"定义FormartSrc()
func FormartSrc()
exec "w"
"C程序,Perl程序,Python程序
if &filetype == 'c'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'cpp'
exec "!astyle --style=java --suffix=none %"
exec "e! %"
elseif &filetype == 'perl'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'py'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
"Java程序
elseif &filetype == 'java'
exec "!astyle --style=java --suffix=none %"
exec "e! %"
elseif &filetype == 'jsp'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'xml'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'html'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
elseif &filetype == 'htm'
exec "!astyle --style=gnu --suffix=none %"
exec "e! %"
endif
endfunc
"结束定义FormartSrc
map <F11> :call FormartSrc()<CR>

"python的高亮显示
"set filetype=python
func Ispython()
exec "w
if &filetype == 'py'
exec "set filetype=python"
endfunc
map<F8> :cal Ispython()<CR>

"java代码补全
autocmd Filetype java set omnifunc=javacomplete#Complete

"-- omnicppcomplete setting --
set nocp 
set completeopt=menu,menuone
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype  in popup window
let OmniCpp_GlobalScopeSearch=1
let OmniCpp_DisplayMode=1
let OmniCpp_DefaultNamespaces=["std"]

3:安装中文帮助包

   下载vimcdoc-1.8.0.tar.gz

   下载地址http://sourceforge.net/projects/vimcdoc/files/vimcdoc/1.8.0/

    解压后按照里面的install文件惊醒安装即可


4:安装ctags, cscope, astyle插件

     直接

 apt-get install ctags
 apt-get install cscope
 apt-get install astyle

    可以草靠这位大神:http://easwy.com/blog/archives/advanced-vim-skills-cscope/,关于cscope的用法等等


5:安装taglist插件

     下载地址:  http://www.vim.org/scripts/script.php?script_id=273

     解压后将里面的文件复制到~/.vim里面即可

     配置一下帮助文件:

启动vim,输入命令
:helptags ~/.vim/doc/taglist.txt

     按F3可出现list窗口


6:安装nerdcommenter批量注释工具

     下载地址: http://www.vim.org/scripts/script.php?script_id=1218

     安装过程同上

     使用:可以用命令行,或者在可是模式下选中后

     \cc:普通注视

     \cm:块注释

     \cs:sexy模式注释

     \cu:取消注释


7:安装omnicppcomplete工具,完成c++代码的提示功能

    下载地址:自己google

    安装过程依然同上

    不过我希望有stl里面的提示即可

    于是可下载cpp_src.bar.bz2  http://www.vim.org/scripts/script.php?script_id=2358

    解压后在其目录里执行

ctags -R --c++-kinds=+p --fields=+iaS --extra=+q
    可生成一个2M左右的tags文件,我将其重命名为stl_tags,并在配置文件中指明了位置,就可以实现自动提示了

    可以参考这位大神:http://www.cnblogs.com/marchtea/archive/2012/10/17/2727852.html 实现stl的高亮


7:安装javacomplete工具,完成java代码的提示功能

     下载地址http://www.vim.org/scripts/script.php?script_id=1785

      解压后用javac命令:javac Rflection.java 生成Rfection.class文件按照下列顺序将文件移动到~/.vim

      autolod里包含: javacomplete.vim, rflection.class

      fplugin里包含java_parser.vim

      在~/.profile里面添加 export CLASSPATH=~/.vim:$CLASSPATH

      即可实现java的自动补全

      python的自动补全据说是vim自带的用ctrl-x, ctrl-o进行全能补全即可,ctrl-p是向已经输入的前文进行匹配,ctrl-n是向      后文进行匹配




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值