入手imac,零零碎碎花了几天时间,终于配置好了vim环境,记录下。
在MAC下,我用了MacVim,打开压缩包,里面有个mvim的脚本,运行后可以在命令行中调用MacVim。
使用插件:
pathogen,Taglist,NERD_tree,snipMate,nerocomplcache等~~~~
每个插件的具体配置就不说了,网上一般都有,主要写两个我配置中出现的问题
1、苹果默认ctags有点问题,需要自己重新下,自己编译或者用port或者homebrew安装都可以,我使用了homebrew。但是没有制定PATH或者做软链接的话,使用的还是MAC自带的ctags,我是用软链接实现。
2、pathogen。按照晚上说明,建立autoload目录,把pathogen.vim放在下面,在.vimrc中,添加
"pathogen
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
记得要在filetype plugin indent on前(没搞清楚为啥)
然后建立bundle,在bundle下建立各个插件的目录,此时发现问题,部分插件能用,但是部分插件没效果,折腾了半天发现,例如我的minibuf插件是这么配置的。
把minibuf.vim放在~/.vim/bundle/minibuf下,这时,minibuf是无效的,对比了其他几个插件,我在~/.vim/bundle/minibuf下在建立个plugin目录,把minibuf.vim放在~/.vim/bundle/minibuf/plugin下,就可以了~~~
下面放上俺的vimrc
set nocompatible
syntax on
colorscheme desert
set guifont=Monaco:h16
"pathogen
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
if has("autocmd")
filetype plugin indent on "根据文件进行缩进
augroup vimrcEx
au!
autocmd FileType text setlocal textwidth=78
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("{1}quot;) |
\ exe "normal! g`\"" |
\ endif
augroup END
else
"智能缩进,相应的有cindent,官方说autoindent可以支持各种文件的缩进,但是效果会比只支持C/C++的cindent效果会差一点,但笔者并没有看出来
set autoindent " always set autoindenting on
endif " has("autocmd")
if(g:iswindows==1) "允许鼠标的使用
"防止linux终端下无法拷贝
if has('mouse')
set mouse=a
endif
au GUIEnter * simalt ~x
endif
set nu
set incsearch
set hlsearch
map <F9> :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>{1}lt;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")
let tagsdeleted=delete("./"."tags")
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")
let csfilesdeleted=delete("./"."cscope.files")
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")
let csoutdeleted=delete("./"."cscope.out")
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") )
silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files"
silent! execute "!cscope -b"
execute "normal :"
if filereadable("cscope.out")
execute "cs add cscope.out"
endif
endif
endfunction
"taglist
let Tlist_Show_One_File=1
let Tlist_Ctags_Cmd='ctags' "因为我们放在环境变量里,所以可以直接执行
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Windos=0
let Tlist_File_Fold_Auto_Close=1 "非当前文件,函数列表折叠隐藏
let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim
map <F3> :silent! Tlist<CR>
"NERD_commenter
let NERDShutUp=1
"Doxygen
map fg : Dox<cr>
let g:DoxygenToolkit_authorName="dantezhu"
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
"minibuf
let g:miniBufExplMapWindowNavVim = 1 "<C-jklh>切换
let g:miniBufExplMapCTabSwitchBufs = 1 "<C-Tab>切换窗口
let g:miniBufExplModSelTarget = 1
"neocomlcach
let g:acp_enableAtStartup = 0
" Use neocomplcache.
let g:neocomplcache_enable_at_startup = 1
" " Use smartcase.
let g:neocomplcache_enable_smart_case = 1
" " Use camel case completion.
let g:neocomplcache_enable_camel_case_completion = 1
" " Use underbar completion.
let g:neocomplcache_enable_underbar_completion = 1
" " Set minimum syntax keyword length.
let g:neocomplcache_min_syntax_length = 4
"turn off auto complete
let g:neocomplcache_disable_auto_complete = 1
"use supertab
let g:SuperTabDefaultCompletionType="context"
"NERD_tree
nmap <F4> :NERDTree <CR>
let NERDTreeWinPos = "right" "where NERD tree window is placed on the screen