原来一直用的那个《屎上最强XXX》的配置
但是一直搞不懂里面写的是什么意思,趁着这两天重装系统的机会,自己重新配(其实去抄别人的)了一份。
http://www.oschina.net/code/snippet_119181_4840
看了一下很符合口味,就借用了。基本没变动,稍微修改了几句,
注:以下带有网址的都是需要去下载这些插件,点击网址进去就有了
另注:貌似Tlist那个网址被我不小心删掉了
再注:使用archlinux的,可以使用yaourt再AUR中找,很多都是以vim-XXX开头的,命令格式如下:
yaourt -Ss vim-XX
yaourt -S vim-XX
vim的自动补齐一直弄不好,有空找个人帮忙教一下,另外有一些插件功能还没想出来怎么用。现在把弄好的贴上。
另外快捷键一多,没熟悉前总是很难受的,所以弄了一个help.txt文档,放在~/.vim/目录下,每次输入<leader>he就可以打开帮助文档。
新增:抽空弄了一下自动补齐,感觉不错,安装插件neocomplcache
在archlinux中,AUR里面也有,名称为 vim-neocomplcache,所以输入命令:
# yaourt -S vim-neocomplcache然后在~/.vimrc中补上一行:
let g:neocomplcache_enable_at_startup = 1
改变:删掉了关于cscope快捷键,使用官网推荐的快捷方式(其实也没怎么用到)
重新修改了几个快捷键,感觉有些用起来还是不舒服
关于快速编译:永不来autotool系列的工具,找了本书结果有300多页,也没那么多精力去看,然后就偷懒装了一个Qt,用Qt自带的qmake工具生成Makefile工具
用法如下:
# qmake -project
# qmake
注:在vim中输入:make可以让vim编译器自动根据当前目录下的Makefile文件进行编译
配置文件~/.vimrc
let mapleader = "m" " 比较习惯用;作为命令前缀,右手小拇指直接能按到 " 把空格键映射成: nmap <space> / " 快捷打开编辑vimrc文件的键盘绑定 map <silent> <leader>ee :e $HOME/.vimrc<cr> autocmd! bufwritepost *.vimrc source $HOME/.vimrc " ^z快速进入shell nmap <C-Z> :shell<cr> ""inoremap <leader>n <esc> " 判断操作系统 if (has("win32") || has("win64") || has("win32unix")) let g:isWin = 1 else let g:isWin = 0 endif " 判断是终端还是gvim if has("gui_running") let g:isGUI = 1 else let g:isGUI = 0 endif "set cursorline "高亮当前行 set nocompatible " 关闭兼容模式 syntax enable " 语法高亮 syntax on filetype plugin on " 文件类型插件 filetype indent on "set shortmess=atI " 去掉欢迎界面 set autoindent autocmd BufEnter * :syntax sync fromstart set nu " 显示行号 set showcmd " 显示命令 set lz " 当运行宏时,在命令执行完成之前,不重绘屏幕 set hid " 可以在没有保存的情况下切换buffer set backspace=eol,start,indent set whichwrap+=<,>,h,l " 退格键和方向键可以换行 "set incsearch " 增量式搜索 set nohlsearch set hlsearch " 高亮搜索 set ignorecase " 搜索时忽略大小写 set magic " 额,自己:h magic吧,一行很难解释 set showmatch " 显示匹配的括号 set nobackup " 关闭备份 set nowb set noswapfile " 不使用swp文件,注意,错误退出后无法恢复 set lbr " 在breakat字符处而不是最后一个字符处断行 set ai " 自动缩进 set si " 智能缩进 set cindent " C/C++风格缩进 set wildmenu set nofen set fdl=10 set cmdheight=4 "设ckspace和光标键跨越行边界 set whichwrap+=<,>,h,l " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位) set mouse=a set selection=exclusive set selectmode=mouse,key "置控制窗口大小 " tab转化为4个字符 set expandtab set smarttab set shiftwidth=4 set tabstop=4 " 不使用beep或flash set vb t_vb= set background=dark set t_Co=256 colorscheme torte set history=400 " vim记住的历史操作的数量,默认的是20 set autoread " 当文件在外部被修改时,自动重新读取 set mouse=a " 在所有模式下都允许使用鼠标,还可以是n,v,i,c等 "在gvim中高亮当前行 if (g:isGUI) set cursorline colorscheme wombat hi cursorline guibg=#333333 hi CursorColumn guibg=#333333 "set guifont=Consolas\ 10 "set guifontwide=Consolas\ 10 set guifont=DejaVu\ Sans\ Mono\ 10 set gfw=DejaVu\ Sans\ Mono\ 10 " 不显示toolbar set guioptions-=T " 不显示菜单栏 "set guioptions-=m endif " 设置字符集编码,默认使用utf8 if (g:isWin) let &termencoding=&encoding " 通常win下的encoding为cp936 set fileencodings=utf8,cp936,ucs-bom,latin1 else set encoding=utf8 set fileencodings=utf8,gb2312,gb18030,ucs-bom,latin1 endif " 状态栏 set laststatus=2 " 总是显示状态栏 highlight StatusLine cterm=bold ctermfg=yellow ctermbg=blue " 获取当前路径,将$HOME转化为~ function! CurDir() let curdir = substitute(getcwd(), $HOME, "~", "g") return curdir endfunction set statusline=[%n]\ %f%m%r%h\ \|\ \ pwd:\ %{CurDir()\}\/%f\ \ \|%=\|\ %l,%c\ %p%%\ \|\ ascii=%b,hex=%b%{((&fenc==\"\")?\"\":\"\ \|\ \".&fenc)}\ \|\ %{$USER}\ @\ %{hostname()}\ " 根据给定方向搜索当前光标下的单词,结合下面两个绑定使用 function! VisualSearch(direction) range let l:saved_reg = @" execute "normal! vgvy" let l:pattern = escape(@", '\\/.*$^~[]') let l:pattern = substitute(l:pattern, "\n$", "", "") if a:direction == 'b' execute "normal ?" . l:pattern . "<cr>" else execute "normal /" . l:pattern . "<cr>" endif let @/ = l:pattern let @" = l:saved_reg endfunction " 用 */# 向 前/后 搜索光标下的单词 vnoremap <silent> * :call VisualSearch('f')<CR> vnoremap <silent> # :call VisualSearch('b')<CR> " 恢复上次文件打开位置 ""set viminfo='10,\"100,:20,%,n~/.viminfo ""au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif " 删除buffer时不关闭窗口 command! Bclose call <SID>BufcloseCloseIt() function! <SID>BufcloseCloseIt() let l:currentBufNum = bufnr("%") let l:alternateBufNum = bufnr("#") if buflisted(l:alternateBufNum) buffer # else bnext endif if bufnr("%") == l:currentBufNum new endif if buflisted(l:currentBufNum) execute("bdelete! ".l:currentBufNum) endif endfunction " 快捷输入 " 自动完成括号和引号 inoremap ( ()<esc>:let leavechar=")"<cr>i inoremap [ []<esc>:let leavechar="]"<cr>i inoremap } {}<esc>:let leavechar="}"<cr>i inoremap { {<esc>o}<esc>:let leavechar="}"<cr>O inoremap ' ''<esc>:let leavechar="'"<cr>i inoremap " ""<esc>:let leavechar='"'<cr>i " 插件窗口的宽度,如TagList,NERD_tree等,自己设置 let s:PlugWinSize = 25 " taglist.vim down lo "设置依次按下 w m两个键打开列表 nmap wm :WMToggle<cr> let Tlist_Show_One_File=1 let Tlist_Exit_OnlyWindow=1 let g:winManagerWindowLayout='FileExplorer|TagList' let Tlist_Use_Right_Window = 0 let Tlist_File_Fold_Auto_Close = 1 let Tlist_GainFocus_On_ToggleOpen = 0 let Tlist_WinWidth = s:PlugWinSize let Tlist_Auto_Open = 0 let Tlist_Display_Prototype = 0 "let Tlist_Close_On_Select = 1 " OmniCppComplete.vim " http://www.vim.org/scripts/script.php?script_id=1520 set completeopt=menu let OmniCpp_ShowPrototypeInAbbr = 1 let OmniCpp_DefaultNamespaces = ["std"] " 逗号分割的字符串 let OmniCpp_MayCompleteScope = 1 let OmniCpp_ShowPrototypeInAbbr = 0 let OmniCpp_SelectFirstItem = 2 " c-j自动补全,当补全菜单打开时,c-j,k上下选择 "imap <expr> <c-u> pumvisible()?"\<C-N>":"\<C-X><C-O>" "imap <expr> <c-i> pumvisible()?"\<C-P>":"\<esc>" " f:文件名补全,l:行补全,d:字典补全,]:tag补全 "imap <C-]> <C-X><C-]> imap <C-F> <C-X><C-F> imap <C-D> <C-X><C-D> imap <C-L> <C-X><C-L> " NERD_commenter.vim " http://www.vim.org/scripts/script.php?script_id=1218 " Toggle单行注释/“性感”注释/注释到行尾/取消注释 map <leader>cc ,c<space> map <leader>cs ,cs map <leader>c$ ,c$ map <leader>cu ,cu "----------------------------------------------------------------- "" plugin - DoxygenToolkit.vim 由注释生成文档,并且能够快速生成函数标准注释 "----------------------------------------------------------------- let g:DoxygenToolkit_authorName="Asins - asinsimple AT gmail DOT com" let g:DoxygenToolkit_briefTag_funcName="yes" map <leader>da :DoxAuthor<CR> map <leader>df :Dox<CR> map <leader>db :DoxBlock<CR> map <leader>dc <End>a /* */<LEFT><LEFT><LEFT> " NERD tree " http://www.vim.org/scripts/script.php?script_id=1658 let NERDTreeShowHidden = 1 let NERDTreeWinPos = "left" let NERDTreeWinSize = s:PlugWinSize nmap wn :NERDTreeToggle<cr> " DoxygenToolkit.vim " http://www.vim.org/scripts/script.php?script_id=987 " 暂时没有使用 " 更新ctags和cscope索引 " href: http://www.vimer.cn/2009/10/把vim打造成一个真正的ide2.html " 稍作修改,提取出DeleteFile函数,修改ctags和cscope执行命令 map <F6> :call Do_CsTag()<cr> function! Do_CsTag() let dir = getcwd() "先删除已有的tags和cscope文件,如果存在且无法删除,则报错。 if ( DeleteFile(dir, "tags") ) return endif if ( DeleteFile(dir, "cscope.files") ) return endif if ( DeleteFile(dir, "cscope.out") ) return endif if(executable('ctags')) silent! execute "!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ." endif if(executable('cscope') && has("cscope") ) if(g:isWin) silent! execute "!dir /s/b *.c,*.cpp,*.h,*.java,*.cs >> cscope.files" else silent! execute "!find . -iname '*.[ch]' -o -name '*.cpp' > cscope.files" endif silent! execute "!cscope -b" execute "normal :" if filereadable("cscope.out") execute "cs add cscope.out" endif endif " 刷新屏幕 execute "redr!" endfunction function! DeleteFile(dir, filename) if filereadable(a:filename) if (g:isWin) let ret = delete(a:dir."\\".a:filename) else let ret = delete("./".a:filename) endif if (ret != 0) echohl WarningMsg | echo "Failed to delete ".a:filename | echohl None return 1 else return 0 endif endif return 0 endfunction " cscope 绑定 if has("cscope") set csto=1 set cst set nocsverb set cscopequickfix=s-,c-,d-,i-,t-,e- if filereadable("cscope.out") cs add cscope.out endif endif "quickfix 配置" map <F3> :cw<cr> map <F2> :cn<cr> " Vimwiki配置 let g:vimwiki_list = [{'path': '~/Dropbox/MyWiki/my_site/', \ 'path-html': '~/Dropbox/MyWiki/my_site_html/', \ 'html-header': '~/Dropbox/MyWiki/templates/header.tpl', \ 'html-footer': '~/Dropbox/MyWiki/templates/footer.tpl'}] let g:vimwiki_camel_case=0 let wiki = {} let wiki.path = '~/Dropbox/MyWiki/my_site/' let wiki.nested_syntaxes = {'python': 'python', 'c++': 'cpp'} let g:vimwiki_list = [wiki] "pythoncomplete配置 autocmd filetype python set omnifunc=pythoncomplete#Complete "定义在插入模式下 "使用ctrl+j为向下一行 inoremap <C-h> <Left> inoremap <C-j> <Down> inoremap <C-k> <Up> inoremap <C-l> <Right> "可以快速保存和退出 nmap <leader>q :q<CR> nmap <leader>w :w<CR> nmap <leader>qq :q!<CR> nmap <leader>wq :wq<CR> " quickly go to help menu of this function nmap <leader>an :Man 3 <cword><CR> " super enter , it can gucikly go to the next line imap e<CR> <End><CR> imap <leader>dd <Esc>ddi imap e; <End>; map <silent> <leader>he :tabnew ~/.vim/help.txt<CR> " "设置F5编译,F6运行 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 "!python %" 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> map <F6> :call RunResult()<CR> " 自动补齐功能,需要先安装neocomplcache let g:neocomplcache_enable_at_startup = 1 imap <F4> <ESC>:A<CR>i nmap <F4> :A<CR>