[经验总结]我的VIM配置文件

Vim配置与使用技巧
本文分享了详细的Vim配置文件内容及自定义快捷键,包括文件编码设置、语法高亮、窗口操作等,并提供了针对不同文件类型的特定配置,如XML文件的格式化设置。

"************************************************************************
"* filename: .vimrc
"* brief:Happy VIMMING!
"* creator:thinkhy
"* date: 2008年 09月 10日 星期三 22:23:30 CST
"* modify: 2010年 01月 02日 星期六 20:00:59 CST
"************************************************************************
setfileencodings=ucs-bom,utf-8,chinese
setfileencoding=utf-8
setgfn=FreeMono/ 14
setawa" 自动保存
setai" 自动缩进
setexpandtab
setshiftwidth=4
settabstop=4



filetypepluginon
syntaxenable" 语法高亮
setai" Auto indent
setsi" Smart indent
setcindent" C缩进
setcino=g0" public private friend 顶格写
setnocompatible" 不与VI兼容
setruler" 显示光标位置
setnobackup" ~文件烦人
setve=all" 逍遥游
"set iskeyword=@,48-57,192-255 "把默认keyword中的_去掉 还是用默认的吧
"不然Ctags不好使
setacd" autochangedir
setstatusline=[%{strftime('%y-%m-%d/ %a')}][%{&ff}][%Y]%k[%{(&fenc==/"/")?&enc:&fenc}%{(&bomb?/",BOM/":/"/")}]%=[Line:%l/%L,Column:%c%V]/ %P
" ===========================================================================================
" Key map

" <C-q> 粘贴系统剪贴板的内容
nmap<C-q>"+p
imap<C-q><ESC>"+p

" Enter 代替 ESC
inoremap<CR><ESC>

" F2 保存文件
nmap<F2>:w<CR>
imap<F2><ESC>:w<CR>

" F3 切换窗口
nmap<F3><C-w>w
imap<F3><ESC><C-w>w

" F4 关闭窗口
nmap<F4><C-w>c
imap<F4><ESC><C-w>c

" F5 Make
nmap<F5>:copen<CR>:make!<CR>
imap<F5><ESC>:copen<CR>:make!<CR>


" F7 调整格式 用得太少 改作ptag
"nmap <F7> :%!indent -kr<CR>
"imap <F7> <ESC>:%!indent -kr<CR>

nmap<F7><C-w>}<CR>
imap<F7><ESC><C-w>}<CR>

" F8 打开taglist
nmap<F8>:TlistToggle<CR>
imap<F8><ESC>:TlistToggle<CR>

" F9 编译链接C/C++文件
nmap<F9>:!g++ % -o %<<CR>
imap<F9><ESC>:!g++ % -o %<<CR>


" F11 打开Winmanager
nmap<F11>:WManager<CR>
imap<F11><ESC>:WManager<CR>

" F12 建立Tag文件
nmap<F12>:!ctags -R --c-kinds=+p --fields=+S<CR>
imap<F12><ESC>:!ctags -R --c-kinds=+p --fields=+S<CR>

" <space> 空格
nmap<space>o<Esc>

" 调整窗口大小
map<Up><Esc>:winc+<CR>
map<Down><Esc>:winc-<CR>
map<Left><Esc>:winc><CR>
map<Right><Esc>:winc<<CR>

nmapF:BufExplorer<CR>
" 水木中收的技巧
" 设置多文件搜索快捷键,搜索完毕后不自动跳转
" 这个在GVIM与GUI的局快捷键冲突,在终端中与终端窗口的快捷键冲突
"nmap <M-f> *:vimgrep //<<c-r><c-w>/>/j **/*.[ch] **/*.txt **/*.cpp<cr>

" 顺序或倒序遍历quickfix中列出的item
nnoremap<F9>:cp<cr>
inoremap<F9><c-o>:cp<cr>
nnoremap<F10> :cn<cr>
inoremap<F10> <c-o>:cn<cr>
"
" For C/C++ file

" Proposed by winmanager plugin
map<c-w><c-f>:FirstExplorerWindow<cr>
map<c-w><c-b>:BottomExplorerWindow<cr>
map<c-w><c-t>:WMToggle<cr>
"=========================================================================================
"技巧
"
" 水木中介绍解决输入法切换的问题
autocmdInsertEnter*setnoimdisable
autocmdInsertLeave*setimdisable

auBufRead,BufNew/home/thinkhy/work/apue.2e/*settags+=/home/thinkhy/work/apue.2e/tags
auBufRead,BufNew/home/thinkhy/work/wine/*settags+=/home/thinkhy/work/wine/wine-1.1.35/tags

auBufRead,BufNewMakefilesetnoexpandtab
auBufRead,BufNewmakefilesetnoexpandtab

" 这个技巧看上去很好,但和我的习惯不符,还是^O和Tab搭配着好用。
" smth VIM版flw 介绍的 Tab用法
" if version >= 700
" nmap <silent> <TAB> <C-W>w:set cursorline<CR>:200sl m<CR>:set nocursorline<CR>
" nmap <silent> <S-TAB> <C-W>p:set cursorline<CR>:200sl m<CR>:set nocursorline<CR>
" else
" nmap <silent> <TAB> <C-W>w
" nmap <silent> <S-TAB> <C-W>p
" endif

"autocmd CmdWinEnter * inoremap <buffer> <Esc> <C-o>:exit<CR><Esc> /| /
"set noimdisable|set insertmode
"autocmd CmdWinLeave * set imdisable | set noinsertmode
"cnoremap <C-space> <C-f>

"imap <Tab> <Space><Space><Space><Space><Space><Space><Space><Space

"===========================================================
" For xml file
"===========================================================
"so ~/vimfiles/plugin/xml.vi
autocmdFileTypexml,xsd,xsl:settabstop=4expandtab

letg:ChineseIMESpaceToggle=1
"let g:ChineseIMEMappingCtrl6=1
setlocalpumheight=1
setlocalcompleteopt=menu,preview,longest
"nmap <F12> :w&&%!xmllint % --format<CR

"imap <F12> <ESC>:%!xmllint % --format<CR

" for C++ tags[09/11/30 thinkhy]
map<C-F12>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>


">=================================================
">=================================================
" [ Added by thinkhy 2010年 01月 02日 星期六 19:54:24 CST]
" 水木VIM版15322贴
"发信人: flw (梨花小蓓蕾), 信区: VIM
"标题: 分享几个我自认为比较得意的自定义快捷键
"发信站: 水木社区 (Mon Dec 28 10:34:46 2009), 站内

" 换标签页
nmap<C-N>:tabnext<CR>
nmap<C-P>:tabprev<CR>

" 换窗口
nmap<silent><TAB><c-w>w:set cursorline<CR>:100sl m<CR>:set nocursorline<CR>
nmap<silent><S-TAB><c-w>p:set cursorline<CR>:100sl m<CR>:set nocursorline<CR>

function! HelpHelper(where )
" 先拿下光标下的文字
letl:word=expand("<cWORD>")

" 再取出疑似函数名/模块名的部分和疑似方法的部分
" /([_a-zA-Z0-9:]/+/)/(->/([_a-zA-Z0-9]/+/)/)/?
letl:lists=matchlist(l:word, "//([_a-zA-Z0-9:]//+//)//(->//([_a-zA-Z0-9]//+//)//)//?")

letl:name=l:lists[1]
letl:method=l:lists[3]

letl:progList=[]

if&ft=="perl"
ifmatch(l:name, "::")!=-1
" 函数里是不可能有 :: 的,不用想了,一定是模块
letl:progList+=[ [ "perldoc -u ", "pod"] ]
elseifstrlen(l:method )
" 有方法的,一定是模块了
letl:progList+=[ [ "perldoc -u ", "pod"] ]
elseifmatch(l:name, "[A-Z]")!=-1
" 有大写字母,那一定是模块了,Perl buildin 函数的名称全都是小写字母的
letl:progList+=[ [ "perldoc -u ", "pod"] ]
else
" 剩下的,有可能是函数,也有可能是模块,
" 但是考虑到这样的模块较少,因此先优先查函数
letl:progList+=[ [ "perldoc -u -f ", "pod"], [ "perldoc -u ", "pod"] ]
endif
endif

if&ft=="python"
letl:progList+=[ [ "python -c /"import sys; a = sys.argv[-1]; b = a.find('.') > -1 and 1 or 0; m = b == 1 and '.'.join(a.split('.')[:-1]) or a; exec( 'import '+m+';help('+a+')' )/" ", "man"] ]
endif

if&ft=="erlang"
ifmatch(l:name, ":")!=-1
" erlang 的模块方法
letl:lists=matchlist(l:name, "//([_a-zA-Z0-9:]//+//)://([_a-zA-Z0-9]//+//)")
letl:name=l:lists[1]
letl:method=l:lists[2]
endif
letl:progList+=[ [ "PAGER=/"col -b/" erl -man ", "man"] ]
endif

letl:progList+=[ [ "PAGER=/"col -b/" man 3 ", "man"] ]
letl:progList+=[ [ "PAGER=/"col -b/" man 2 ", "man"] ]
letl:progList+=[ [ "PAGER=/"col -b/" man ", "man"] ]

letl:found=0
" 下面调用外部命令,取帮助信息

" [Added by thinkhy 10/01/02]
if&ft=="vim"
echomsg"Iamvim"
try
execute" h ".l:word
catch/foo/
endtry
execute"wincmd p"
return
endif
" [End thinkhy]

forl:proginl:progList
letl:progName=l:prog[0]
letl:fileType=l:prog[1]
letl:cmd=l:progName.l:name
letl:lines=system(l:cmd )
if!v:shell_error
ifa:where==?"inNewTab"
tabe
elseifa:where==?"Vertical"
rightbelownew
else
abovenew
endif

setbuftype=nofile
setts=8
execute"set ft=".l:fileType
callappend(0, split(l:lines, "/n"))
normalgg
ifstrlen(l:method)" 跳转到方法
ifl:fileType=="pod"
" regex: /(=item/d*/s/+/)/@<= />
callsearch("//(=item//d*//s//+//)//@<=".l:method ."//>")
elseifl:fileType=="man"
" regex: /(^/s/+/)/@<=l:method/>
callsearch("//(^//s//+//)//@<=".l:method ."//>")
endif
endif

letl:found=1
break
endif
endfor

if!l:found
echohlErrorMsg|echomsg"^_^ 没有帮助信息。"|echohlNone
endif

endfunction

" vim 内打开 man/perldoc/erl -man/python help
autocmdFileTypec,perl,erlang,python,vimnmap<silent>K:call HelpHelper( "" )<CR>
autocmdFileTypec,perl,erlang,python,vimnmap<silent>gK:call HelpHelper( "InNewTab" )<CR>

">==========================================================================
"发信人: Dieken (风催草低 - 明月何尝不照人), 信区: VIM
"标题: Re: 分享几个我自认为比较得意的自定义快捷键
"发信站: 水木社区 (Mon Dec 28 12:00:38 2009), 站内
" 我也来:

" Press v in quickfix window to preview
" 虽然没看懂zz:的意思,好使
auFileTypeqf:nnoremap<buffer>v<Enter>zz:wincmd p<Enter>

" for gf command to open java source file at import clause
auFileTypejava:setsuffixesadd+=.java

"
" nnoremap <c-m> :redir @a<CR>:g//<CR>:redir END<CR>:new<CR>:put! a<CR><CR>

" 将搜索结果放在copen窗口
" ----------------------------------------------------------------------------
" * :lop[en] [height] 打开一个窗口显示当前窗口的位置列表。只有当前窗口有位置
" * 列表的情况才能用。你可以同时打开多于一个的位置列表窗
" * 口。除此以外,和 ":copen"相同。
" ----------------------------------------------------------------------------
nnoremap<c-m>:g//laddexpr expand("%") . ":" . line(".") . ":" .getline(".")<CR>:lopen<CR><CR>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值