一个适合自己的vim设置。

经过3天的煎熬,找各种资料终于弄了个基本的符合自己vim配置。

这篇文章以后会不定时更新。

用到的插件:

a.vim    //头文件和编程文件之间切换
bufexplorer.vim      //文件浏览器,基本不用
color_sample_pack.vim   //各种颜色主题
csExplorer.vim                //
DoxygenToolkit.vim         //个性文本生成工具,知道大概干什么,以后再说
genutils.vim 
list
lookupfile.vim                 //查找文件插件
mark.vim                        //标记高亮显示
minibufexpl.vim              //很好用的打开文件显示浏览器
NERD_commenter.vim   //注释插件
NERD_tree.vim
project.vim                    //工程目录插件
ShowFunc.vim               //显示函数插件,还没怎么用
taglist.vim                     //前提是安装了ctags,此插件才好用,Exburant ctags
winfileexplorer.vim        //winmanager里的,winmanager可以控制taglist和bufexplorer的显示。
winmanager.vim
wintagexplorer.vim

vimrc文件:

"display the cursor
"set ruler
set nocp
filetype plugin on

" detect the filetype
" this sentence eq   filetype on, filetype plugin on, filetype indent on
filetype plugin indent on
set nocompatible

set foldmethod=syntax

"set color display
set t_Co=256


"Set mapleader
"when use just in normal mode type ,ee 
let mapleader = ","

"Fast reloading of the .vimrc
map <silent> <leader>ss :source ~/.vimrc<cr>
"Fast editing of .vimrc
map <silent> <leader>ee :e ~/.vimrc<cr>
"When .vimrc is edited, reload it
autocmd! bufwritepost .vimrc source ~/.vimrc

""""""""""""""""""""""""""""
"     MiniBufferExplorer   "
""""""""""""""""""""""""""""
let g:miniBufExplMapWindowNavVim=1
let g:miniBufExplMapWindowNavArrows=1
let g:miniBufExplMapCTabSwitchBufs=1
"let g:miniBufExplModSelTarget=1 


"进行Taglist的设置
"TlistUpdate可以更新tags
map <F3> :silent! Tlist<CR>
"按下F3就可以呼出了
let Tlist_Ctags_Cmd='/usr/bin/ctags' 
"因为我们放在环境变量里,所以可以直接执行
let Tlist_Use_Right_Window=1
"让窗口显示在右边,0的话就是显示在左边
let Tlist_Show_One_File=1
"让taglist可以同时展示多个文件的函数列表
let Tlist_File_Fold_Auto_Close=1
"非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1
"当taglist是最后一个分割窗口时,自动推出vim
"是否一直处理tags.1:处理;0:不处理
let Tlist_Process_File_Always=0
"不是一直实时更新tags,因为没有必要
let Tlist_Inc_Winwidth=0


"设置字体
"set guifont=DejaVu\ Sans\ Mono\ 10
set guifont=Consolas\ 11
" 开启语法高亮
syntax enable
syntax on
"设置了在窗口右侧何处开始换行没有\n符号,textwidth有\n
set wrapmargin=10

"在代码使用4个空格代替TAB符
autocmd FileType c,cpp,py set shiftwidth=4 | set expandtab

"zzg added 
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
"set laststatus=2
"imap <C-s> <ESC>:w<cr>a

set shiftwidth=4
"set indent length

set expandtab
" set use a series of backspaces to  replace tab

set tabstop=4
" set when press a tab how many backspaces will skip

"关闭vi兼容模式
"set nocp

" 自动切换目录
set autochdir
" 打开行号显示
set nu
" 设置文字编码自动识别
set fencs=utf-8,cp936
" 使用鼠标
set mouse=a
" 设置高亮搜索
set hlsearch
" 设置代码折叠
"set fdm=indent
"set foldmethod=syntax
"autocmd FileType c,cpp  setl fdm=syntax | setl fen 
" 输入字符串就显示匹配点
set incsearch
" 输入的命令显示出来,看的清楚些。
set showcmd
" 选择配色方案
"hi Nomal ctermfg=Grey ctermbg=Black
colorscheme darkburn
"colorscheme darkblue
"colorscheme morning

""""""""""""""""""""""""""""""
" BufExplorer
""""""""""""""""""""""""""""""
"let g:bufExplorerDefaultHelp=0       " Do not show default help.
"let g:bufExplorerShowRelativePath=1  " Show relative paths.
"let g:bufExplorerSortBy='mru'        " Sort by most recently used.
"let g:bufExplorerSplitRight=0        " Split left.
"let g:bufExplorerSplitVertical=1     " Split vertically.
"let g:bufExplorerSplitVertSize=30    " Split width
"let g:bufExplorerUseCurrentWindow=1  " Open in new window.
"autocmd BufWinEnter \[Buf\ List\] setl nonumber 

"打开当前目录文件列表
""""""""""""""""""""""""""""""
" netrw setting
""""""""""""""""""""""""""""""
let g:netrw_winsize = 30
nmap <silent> fe :Sexplore!<cr> 


let g:LookupFile_TagExpr = '"./filenametags"' 



"""""""""""""""""""""""""""""
" WinManager setting
"""""""""""""""""""""""""""""
let g:winManagerWindowLayout = "FileExplorer|TagList"
let g:winManagerWidth = 30
let g:defaultExplorer = 0
nmap <C-W><C-F> :FirstExplorerWindow<cr>
nmap <C-W><C-B> :BottomExplorerWindow<cr>
nmap <silent> wm :WMToggle<cr>

""""""""""""""""""""""""""""""
" lookupfile setting
""""""""""""""""""""""""""""""
let g:LookupFile_MinPatLength = 2               "最少输入2个字符才开始查找
let g:LookupFile_PreserveLastPattern = 0        "不保存上次查找的字符串
let g:LookupFile_PreservePatternHistory = 1     "保存查找历史
let g:LookupFile_AlwaysAcceptFirst = 1          "回车打开第一个匹配项目
let g:LookupFile_AllowNewFiles = 0              "不允许创建不存在的文件
if filereadable("./filenametags")                "设置tag文件的名字
let g:LookupFile_TagExpr = '"./filenametags"'
endif
"映射LookupFile为,lk
nmap <silent> <leader>lk :LUTags<cr>
"映射LUBufs为,ll
nmap <silent> <leader>ll :LUBufs<cr>
"映射LUWalk为,lw
nmap <silent> <leader>lw :LUWalk<cr>

" lookup file with ignore case
function! LookupFile_IgnoreCaseFunc(pattern)
    let _tags = &tags
    try
        let &tags = eval(g:LookupFile_TagExpr)
        let newpattern = '\c' . a:pattern
        let tags = taglist(newpattern)
    catch
        echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE
        return ""
    finally
        let &tags = _tags
    endtry

    " Show the matches for what is typed so far.
    let files = map(tags, 'v:val["filename"]')
    return files
endfunction
let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc' 


""""""""""""""""""""""""""""""
" mark setting
""""""""""""""""""""""""""""""
nmap <silent> <leader>hl <Plug>MarkSet
vmap <silent> <leader>hl <Plug>MarkSet
nmap <silent> <leader>hh <Plug>MarkClear
vmap <silent> <leader>hh <Plug>MarkClear
nmap <silent> <leader>hr <Plug>MarkRegex
vmap <silent> <leader>hr <Plug>MarkRegex 

"Quickfix hotkey
autocmd FileType c,cpp  map <buffer> <leader><space> :w<cr>:make<cr>
nmap <leader>cn :cn<cr>
nmap <leader>cp :cp<cr>
nmap <leader>cw :cw 10<cr> 

"在当前文件中快速查找光标下的单词: 
nmap <leader>lv :lv /<c-r>=expand("<cword>")<cr>/ %<cr>:lw<cr> 


map <F12> :call Do_CsTag()<CR>
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>:copen<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>:copen<CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR>
nmap <C-@>f :cs find f <C-R>=expand("<cfile>")<CR><CR>:copen<CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>:copen<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>:copen<CR>
function Do_CsTag()
    let dir = getcwd()
    if filereadable("tags")
        if(g:iswindows==1)
            let tagsdeleted=delete(dir."\\"."tags")
        else
            let tagsdeleted=delete("./"."tags")
        endif
        if(tagsdeleted!=0)
            echohl WarningMsg | echo "Fail to do tags! I cannot delete the tags" | echohl None
            return
        endif
    endif
    if has("cscope")
        silent! execute "cs kill -1"
    endif
    if filereadable("cscope.files")
        if(g:iswindows==1)
            let csfilesdeleted=delete(dir."\\"."cscope.files")
        else
            let csfilesdeleted=delete("./"."cscope.files")
        endif
        if(csfilesdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.files" | echohl None
            return
        endif
    endif
    if filereadable("cscope.out")
        if(g:iswindows==1)
            let csoutdeleted=delete(dir."\\"."cscope.out")
        else
            let csoutdeleted=delete("./"."cscope.out")
        endif
        if(csoutdeleted!=0)
            echohl WarningMsg | echo "Fail to do cscope! I cannot delete the cscope.out" | echohl None
            return
        endif
    endif
    if(executable('ctags'))
        "silent! execute "!ctags -R --c-types=+p --fields=+S *"
        silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ."
    endif
    if(executable('cscope') && has("cscope") )
        if(g:iswindows!=1)
            silent! execute "!find . -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.java' -o -name '*.cs' > cscope.files"
        else
            silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
        endif
        silent! execute "!cscope -b"
        execute "normal :"
        if filereadable("cscope.out")
            execute "cs add cscope.out"
        endif
    endif
endfunction




" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
autocmd CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif



" set something for ominicomplete
set completeopt=longest,menu 

"对NERD_commenter的设置
let NERDShutUp=1

map fg :Dox<cr>
let g:DoxygenToolkit_authorName="zzg"
let g:DoxygenToolkit_licenseTag="My own license\<enter>"
let g:DoxygenToolkit_undocTag="DOXIGEN_SKIP_BLOCK"
let g:DoxygenToolkit_briefTag_pre = "@brief\t"
let g:DoxygenToolkit_paramTag_pre = "@param\t"
let g:DoxygenToolkit_returnTag = "@return\t"
let g:DoxygenToolkit_briefTag_funcName = "no"
let g:DoxygenToolkit_maxFunctionProtoLines = 30



" mapping omini
inoremap <expr> <CR>       pumvisible()?"\<C-Y>":"\<CR>"
inoremap <expr> <C-J>      pumvisible()?"\<PageDown>\<C-N>\<C-P>":"\<C-X><C-O>"
inoremap <expr> <C-K>      pumvisible()?"\<PageUp>\<C-P>\<C-N>":"\<C-K>"
inoremap <expr> <C-U>      pumvisible()?"\<C-E>":"\<C-U>" 


set tags+=~/.vim/stl_tags

"set paste  if set this the omnicomplete will not work 
"remember to the last position you edit zzg
if has("autocmd")
       autocmd BufRead *.txt set tw=78
       autocmd BufReadPost *
        \ if line("'\"") > 0 && line ("'\"") <= line("$") |
        \   exe "normal g'\"" |
        \ endif
endif

总结一下安装过程中遇到的问题:

   安装ctags由于以前安装过emacs,所以有了emacs的ctags,我误以为是exburant ctags已经安装了,结果错了很长时间,要安装Exburant ctags,也就是正常情况下的ctags。

   安装cscope时make错误,就没安,继续往下,但是cpp的自动补全不好使。后来查到cscope缺少的相关软件有:

   bison , flex  lib curses-dev 什么的

   用 apt-cache search keywords 就能找到了.然后再安装对应的包就行了。

最后设置vim下用256色,并用了一个非常好看的颜色主题:darkburn.vim

有两个网站关于vim讲的非常好:

http://www.vimer.cn/

http://easwy.com/blog/     很敬佩这位大牛!!

下载插件的官网是:搜一下想找的插件立马就会出来,官网很强大。

http://www.vim.org/scripts/

猜你喜欢

转载自zzgthk.iteye.com/blog/860620