vim 配置
1、http://hessian.cn/p/1026.html 这边博客上有一些配置是可以借鉴的。
2、说说我的配置。
(a)先配置vim插件管理工具pathogen。
项目地址:https://github.com/tpope/vim-pathogen
安装方法:
- 在
.vim文件夹下建立autoload和bundle目录 - 从下载地址获取pathogen.vim文件,将其复制到autoload目录下
- 在
.vimrc文件中添加配置。
3、安装其他配置插件。到 bundle目录下执行git命令,然后在.vimrc下配置相关插件的配置。
以下是我安装的几个插件和相应的配置:

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""新文件标题"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "新建.c,.h,.sh,.java文件,自动插入文件头 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" ""定义函数SetTitle,自动插入文件头 func SetTitle() "如果文件类型为.sh文件 if &filetype == 'sh' call setline(1,"\#########################################################################") call append(line("."), "\# File Name: ".expand("%")) call append(line(".")+1, "\# Author: xxx") call append(line(".")+2, "\# mail: jason@xxx.com ") call append(line(".")+3, "\# Created Time: ".strftime("%c")) call append(line(".")+4, "\#########################################################################") call append(line(".")+5, "\#!/bin/bash") call append(line(".")+6, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name: ".expand("%")) call append(line(".")+1, " > Author: xxx") call append(line(".")+2, " > Mail: jason@xxx.com ") call append(line(".")+3, " > Created Time: ".strftime("%c")) call append(line(".")+4, " ************************************************************************/") call append(line(".")+5, "") endif if &filetype == 'cpp' call append(line(".")+6, "#include<iostream>") call append(line(".")+7, "using namespace std;") call append(line(".")+8, "") endif if &filetype == 'c' call append(line(".")+6, "#include<stdio.h>") call append(line(".")+7, "") endif "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G endfunc """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "键盘命令 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" nmap <leader>w :w!<cr> nmap <leader>f :find<cr> " 映射全选+复制 ctrl+a map <C-A> ggVGY map! <C-A> <Esc>ggVGY map <F12> gg=G " 选中状态下 Ctrl+c 复制 vmap <C-c> "+y "去空行 nnoremap <F2> :g/^\s*$/d<CR> "比较文件 nnoremap <C-F2> :vert diffsplit "新建标签 map <M-F2> :tabnew<CR> "列出当前目录文件 map <F3> :tabnew .<CR> "打开树状文件目录 map <C-F3> \be "C,C++ 按F5编译运行 map <F5> :call CompileRunGcc()<CR> func! CompileRunGcc() exec "w" if &filetype == 'c' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype == 'sh' :!./% endif endfunc "C,C++的调试 map <F8> :call Rungdb()<CR> func! Rungdb() exec "w" exec "!g++ % -g -o %<" exec "!gdb ./%<" endfunc """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ""实用设置 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 设置当文件被改动时自动载入 set autoread " quickfix模式 autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr> "代码补全 set completeopt=preview,menu "允许插件 filetype plugin on "共享剪贴板 set clipboard+=unnamed " pathogen 插件管理器配置 execute pathogen#infect() syntax on filetype plugin indent on " 文件夹浏览器 " autocmd vimenter * NERDTree " 显示行号 set number " 自动补全配置 "Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)! " Disable AutoComplPop. let g:acp_enableAtStartup = 0 " Use neocomplcache. let g:neocomplcache_enable_at_startup = 1 " Use smartcase. let g:neocomplcache_enable_smart_case = 1 " Set minimum syntax keyword length. let g:neocomplcache_min_syntax_length = 3 let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*' " Enable heavy features. " Use camel case completion. "let g:neocomplcache_enable_camel_case_completion = 1 " Use underbar completion. "let g:neocomplcache_enable_underbar_completion = 1 " Define dictionary. let g:neocomplcache_dictionary_filetype_lists = { \ 'default' : '', \ 'vimshell' : $HOME.'/.vimshell_hist', \ 'scheme' : $HOME.'/.gosh_completions' \ } " Define keyword. if !exists('g:neocomplcache_keyword_patterns') let g:neocomplcache_keyword_patterns = {} endif let g:neocomplcache_keyword_patterns['default'] = '\h\w*' " Plugin key-mappings. inoremap <expr><C-g> neocomplcache#undo_completion() inoremap <expr><C-l> neocomplcache#complete_common_string() " Recommended key-mappings. " <CR>: close popup and save indent. inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR> function! s:my_cr_function() return neocomplcache#smart_close_popup() . "\<CR>" " For no inserting <CR> key. "return pumvisible() ? neocomplcache#close_popup() : "\<CR>" endfunction " <TAB>: completion. inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>" " <C-h>, <BS>: close popup and delete backword char. inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>" inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>" inoremap <expr><C-y> neocomplcache#close_popup() inoremap <expr><C-e> neocomplcache#cancel_popup() " Close popup by <Space>. "inoremap <expr><Space> pumvisible() ? neocomplcache#close_popup() : "\<Space>" " For cursor moving in insert mode(Not recommended) "inoremap <expr><Left> neocomplcache#close_popup() . "\<Left>" "inoremap <expr><Right> neocomplcache#close_popup() . "\<Right>" "inoremap <expr><Up> neocomplcache#close_popup() . "\<Up>" "inoremap <expr><Down> neocomplcache#close_popup() . "\<Down>" " Or set this. "let g:neocomplcache_enable_cursor_hold_i = 1 " Or set this. "let g:neocomplcache_enable_insert_char_pre = 1 " AutoComplPop like behavior. "let g:neocomplcache_enable_auto_select = 1 " Shell like behavior(not recommended). "set completeopt+=longest "let g:neocomplcache_enable_auto_select = 1 "let g:neocomplcache_disable_auto_complete = 1 "inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>" " Enable omni completion. autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS autocmd FileType python setlocal omnifunc=pythoncomplete#Complete autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags " Enable heavy omni completion. if !exists('g:neocomplcache_force_omni_patterns') let g:neocomplcache_force_omni_patterns = {} endif let g:neocomplcache_force_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::' let g:neocomplcache_force_omni_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)' let g:neocomplcache_force_omni_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::' " For perlomni.vim setting. " https://github.com/c9s/perlomni.vim let g:neocomplcache_force_omni_patterns.perl = '\h\w*->\h\w*\|\h\w*::' " snippet配置 " execute vam#ActivateAddons(['neosnippet', 'neosnippet-snippets']) " Plugin key-mappings. imap <C-k> <Plug>(neosnippet_expand_or_jump) smap <C-k> <Plug>(neosnippet_expand_or_jump) xmap <C-k> <Plug>(neosnippet_expand_target) " SuperTab like snippets behavior. imap <expr><TAB> neosnippet#expandable_or_jumpable() ? \ "\<Plug>(neosnippet_expand_or_jump)" \: pumvisible() ? "\<C-n>" : "\<TAB>" smap <expr><TAB> neosnippet#expandable_or_jumpable() ? \ "\<Plug>(neosnippet_expand_or_jump)" \: "\<TAB>" " For conceal markers. if has('conceal') set conceallevel=2 concealcursor=niv endif " Enable snipMate compatibility feature. let g:neosnippet#enable_snipmate_compatibility = 1 " let g:neosnippet#disable_runtime_snippets =1 " Tell Neosnippet about the other snippets let g:neosnippet#snippets_directory='~/.vim/bundle/vim-snippets/snippets'
vim效果图:

posted on 2015-08-02 19:59 NewPanderKing 阅读(347) 评论(0) 收藏 举报
浙公网安备 33010602011771号