" C-@+参数 <F7>生成tags,<F8>打开taglist(C-F8打开目录),<F9>编译运行,C-<F9>编译(make),<F9><F9>-debug;<F6>-打开quickwind,<F6><F6>关闭, " :cp上一个错误,:cn下一个错误 "全文查找替换 map <C-f> :%s/ imap <C-f> <Esc><C-f> ":%s/vivian/sky/(等同于 :g/vivian/s//sky/) 替换每一行的第一个 vivian 为 sky ":%s/vivian/sky/g(等同于 :g/vivian/s//sky/g) 替换每一行中所有 vivian 为 sky "取消查找高亮 map <C-z> :nohl<CR> imap <C-z> <Esc><C-z> "查找过后总是查找内容高亮,这个映射能令它快速消失。 map <C-a> ggvG<CR> imap <C-a> <Esc><C-a> "全选 map <C-c> "+yG<CR> imap <C-c> <Esc><C-c> "复制。 map <C-g> :w<CR> imap <C-g> <Esc><C-g> ":保存 map <C-k> :wq<CR> imap <C-k> <Esc><C-k> "保存并退出 map <C-l> :q!<CR> imap <C-l> <Esc><C-l> "不保存退出 map <C-v> "+p<CR> imap <C-v> <Esc><C-v> "粘贴。 nnoremap <F8> :TlistToggle <cr> "打开taglist "map <C-t> :TlistToggle<CR> "imap <C-t> <Esc><C-t> "快速开关Taglist窗口。 "ctrl+w,w:按住ctrl键,同时按下两次w键,从一个窗口切换到另一个窗口 map <C-n> :vnew<CR> imap <C-n> <Esc><C-n> "新建一个文件 ":vs(开启另一个窗口察看同一文件) ":vs 文件名(开启另一个窗口察看指定文件) set helplang=cn set hlsearch " 搜索时忽略大小写,但在有一个或以上大写字母时仍大小写敏感 set ignorecase set smartcase " 搜索到文件两端时不重新搜索 set nowrapscan " 实时搜索 set incsearch syntax on set bg=dark set nu set showmode set ruler set autoindent set backspace=2 set smartindent set magic set spelllang=en set ru filetype plugin indent on set completeopt=longest,menuone set nocp set nocompatible set cindent shiftwidth=2 set shiftwidth=4 set report=0 set fdm=indent "zc 关闭当前打开的折叠 "zo 打开当前的折叠 "zm 关闭所有折叠 "zM 关闭所有折叠及其嵌套的折叠 "zr 打开所有折叠 "zR 打开所有折叠及其嵌套的折叠 "zd 删除当前折叠 "zE 删除所有折叠 "zj 移动至下一个折叠 "zk 移动至上一个折叠 "zn 禁用折叠 "zN 启用折叠 " 设置折叠区域的宽度 set foldcolumn=0 " 设置折叠层数为 setlocal foldlevel=1 " 新建的文件,刚打开的文件不折叠 autocmd! BufNewFile,BufRead * setlocal nofoldenable "设置代码块折叠后显示的行数 set foldexpr=1 "F6为quickfix,查看详细信息, 两次F6关闭详细信息 map <F6> :cw<CR> map <F6><F6> :ccl<CR> set makeprg=g++\ -Wall\ -o\ %<.exe\ % autocmd FileType c,cpp map <C-F9> :w<cr>:make<cr> map<F9> :call CompileRun()<CR> map <F9><F9> :call Debug()<CR> func! CompileRun() exec "w" if &filetype=='cpp' exec "!g++ % -g -o %<.exe" exec "!./%<.exe" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype=='ruby' exec "!ruby %<.rb" exec "!ruby %<.rb" elseif &filetype == "haskell" exec "!ghc --make %<.hs -o %<" exec "! %<.exe" elseif &filetype == "perl" exec "!perl %<.pl" exec "!perl %<.pl" elseif &filetype == "python" exec "!python %<.py" exec "!python %<.py" elseif &filetype == "lua" exec "!lua %<.lua" exec "!lua %<.lua" elseif &filetype == "sh" exec "!bash %<.sh" exec "!bash %<.sh" elseif &filetype == "go" exec "!gccgo -Wall %<.go -o %<" exec "! ./%<" elseif &filetype == "make" exec "!colormake" exec "! ./app" elseif &filetype == "io" exec "!io %<.io" exec "!io %<.io" endif endfunc "定义Debug函数,用来调试小程序 func Debug() exec "w" if &filetype == 'c' "exec "!rm %<.exe" exec "!gcc % -g -o %<.exe" exec "!gdb %<.exe" elseif &filetype == 'cpp' "exec "!rm %<.exe" exec "!g++ % -g -o %<.exe" exec "!gdb %<.exe" elseif &filetype == 'java' "exec "!rm %<.class" exec "!javac %" exec "!jdb %<" endif endfunc "括号自动补全 ":inoremap ( ()<ESC>i " :inoremap ) <c-r>=ClosePair(')')<CR> :inoremap { {}<ESC>i :inoremap } <c-r>=ClosePair('}')<CR> " :inoremap [ []<ESC>i " :inoremap ] <c-r>=ClosePair(']')<CR> ":inoremap < <><ESC>i ":inoremap > <c-r>=ClosePair('>')<CR> function ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endf "" 类似于AutoComplPop用法 . let g:acp_enableAtStartup = 0 let g:neocomplcache_enable_at_startup = 1 let g:neocomplcache_enable_smart_case = 1 let g:neocomplcache_enable_underbar_completion = 1 let g:neocomplcache_enable_camel_case_completion = 1 let g:neocomplcache_auto_completion_start_length = 2 let g:neocomplcache_min_keyword_length = 1 let g:neocomplcache_min_syntax_length = 1 "set taglist let Tlist_Show_Menu = 1 let Tlist_Use_LEFT_Window=1 let Tlist_File_Fold_Auto_Close=1 let Tlist_Show_One_File=1 let Tlist_GainFocus_On_ToggleOpen=1 let Tlist_Exit_OnlyWindow=1 "NERD Tree let NERDChristmasTree=1 let NERDTreeAutoCenter=1 let NERDTreeMouseMode=2 let NERDTreeShowBookmarks=1 let NERDTreeShowFiles=1 let NERDTreeShowHidden=1 let NERDTreeShowLineNumbers=1 let NERDTreeWinPos='left' let NERDTreeWinSize=30 nnoremap <C-F8> :NERDTreeToggle <cr> "下面是对windowsManager插件的相关配置" let g:winManagerWindowLayout='TagList' "let g:winManagerWindowLayout='FileExplorer|TagList' let g:winManagerWidth = 30 let g:defaultExplorer = 0 "nnoremap <silent> <F8> :WMToggle<cr> """""""""""""""""""""""""""""" " 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 = 20 " Split width let g:bufExplorerUseCurrentWindow=1 " Open in new window. set tags=tags set tags+=/usr/bin/tags set tags+=/.tags set tags+=/usr/include/c++/tags set tags+=/usr/share/vim/stltag set autochdir "-- omnicppcomplete setting -- set path+=./ set path+=/usr/share/vim/ highlight Pmenu guibg=darkgrey guifg=black highlight PmenuSel guibg=lightgrey guifg=black 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"] " add any cscope database in current directory if filereadable("cscope.out") cs add cscope.out "else add the database pointed to by environment variable elseif $CSCOPE_DB != "" cs add $CSCOPE_DB endif map <F7> :call Do_CsTag()<CR> nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR> nmap <C-@>g :cg 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> 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 "java 补全 setlocal completefunc=javacomplete#CompleteParamsInfo autocmd FileType c set omnifunc=ccomplete#Complete autocmd FileType css set omnifunc=csscomplete#CompleteCSS autocmd FileType html set omnifunc=htmlcomplete#CompleteTags autocmd FileType java set omnifunc=javacomplete#Complete autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS autocmd FileType php set omnifunc=phpcomplete#CompletePHP autocmd FileType python set omnifunc=pythoncomplete#Complete autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags autocmd FileType java inoremap <buffer> ..<C-X><C-O><C-P> "txtbrower au BufRead,BufNewFile *.log setlocal ft=txt let tlist_txt_settings = 'txt;c:content;f:figures;t:tables' au BufRead,BufNewFile *.txt setlocal ft=txt au BufRead,BufNewFile *.txt runtime ftplugin/txtfmt.vim au BufRead,BufNewFile *.txt runtime syntax/txtfmt.vim let TxtBrowser_Dict_Url='http://dict.cn/text' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => General """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Sets how many lines of history VIM has to remember set history=700 " Enable filetype plugins filetype plugin on filetype indent on " Set to auto read when a file is changed from the outside set autoread " With a map leader it's possible to do extra key combinations " like <leader>w saves the current file "let mapleader = "," "let g:mapleader = "," " Fast saving "nmap <leader>w :w!<cr> """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => VIM user interface """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Set 7 lines to the cursor - when moving vertically using j/k set so=7 " Turn on the WiLd menu set wildmenu " Ignore compiled files set wildignore=*.o,*~,*.pyc "Always show current position set ruler " Height of the command bar set cmdheight=2 " A buffer becomes hidden when it is abandoned set hid " Configure backspace so it acts as it should act set backspace=eol,start,indent ""set whichwrap+=<,>,h,l " Ignore case when searching set ignorecase " When searching try to be smart about cases set smartcase " Highlight search results set hlsearch " Makes search act like search in modern browsers set incsearch " Don't redraw while executing macros (good performance config) set lazyredraw " For regular expressions turn magic on set magic " Show matching brackets when text indicator is over them " set showmatch " How many tenths of a second to blink when matching brackets set mat=2 " No annoying sound on errors set noerrorbells set novisualbell set t_vb= set tm=500 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Colors and Fonts """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Enable syntax highlighting syntax enable " colorscheme evening set background=dark " Set extra options when running in GUI mode if has("gui_running") set guioptions-=T set guioptions+=e set t_Co=256 set guitablabel=%M\ %t endif "解决vim中文乱码方法: set fileencodings=utf-8,gb2312,gbk,gb18030 set termencoding=utf-8 set encoding=prc " Set utf8 as standard encoding and en_US as the standard language set encoding=utf8 ""set guifont=:h100 ""set guifont=Monaco:h18 " Use Unix as the standard file type set ffs=unix,dos,mac """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Files, backups and undo """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Turn backup off, since most stuff is in SVN, git et.c anyway... set nobackup set nowb set noswapfile """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Text, tab and indent related """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Use spaces instead of tabs set expandtab " Be smart when using tabs ;) set smarttab " 1 tab == 4 spaces set shiftwidth=4 set tabstop=4 " Linebreak on 500 characters set lbr set tw=500 set ai "Auto indent set si "Smart indent set wrap "Wrap lines """""""""""""""""""""""""""""" " => Status line """""""""""""""""""""""""""""" " Always show the status line set laststatus=2 " Format the status line set statusline=\%F%m%r%h\ \ \ %w\ASCII=%b\ [line=%4l/%4L\ \ \ col=%3c/%3{col(\"$\")-1}][%p%%] ""set statusline=(%02n)%t%m%r%h%w\[%{&ff}:%{&enc}:%Y]\[line=%4l/%04L\ col=%3c/%03{col(\"$\")-1}][%p%%] ""set statusline=%F%m%r,%Y,%{&fileformat}\ \ \ ASCII=\%b,HEX=\%B\ \ \ %l,%c%V\ %p%%\ \ \ [\ %L\ lines\ in\ all\ ] " Return to last edit position when opening files (You want this!) autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif " Remember info about open buffers on close set viminfo^=% """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Spell checking """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Pressing ,ss will toggle and untoggle spell checking map <leader>ss :setlocal spell!<cr> " Opens a new tab with the current buffer's path " Super useful when editing files in the same directory map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/ "Change work dir to current dir autocmd BufEnter * cd %:p:h