" vim 配置文件
colorscheme morning " 09/07/18 早上颜色不错
set shiftwidth=4
set tabstop=4
set expandtab
"set gfn=FreeMono/ 12
"set fileencoding=utf-8
" set encoding=cp936
" 为了显示utf-16的文本,将encoding改为utf-8 09/10/28
" set encoding=utf-8 改成utf-8有危险,普通cp936编码的打不开,因编码转换失败而清空文件内容
" 发信人: WaterMonster (水怪), 信区: VIM
" 标 题: Re: windows下乱码解决之法
" 发信站: 水木社区 (Sun Jan 24 14:48:48 2010), 站内
" 补充一下,这个办法对于gvim 的windows下还少了一些,可以看到菜单,文本都是中文的
" 但提示语言还是乱码,所以要加上language messages zh_cn.utf-8
" WaterMonster的方法不好使 [10/01/02 thinkhy]
" Window下打开Utf-8的方法暂时还没找到 找到了,安装fencview.vim插件 [10/02/04 thinkhy]
set encoding=chinese
set termencoding=chinese
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-16,utf-8,cp936,gb18030,big5,euc-jp,sjis,euc-kr,ucs-2le,latin1
"set langmenu=zh_CN.utf-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"language message zh_cn.utf-8
"autocmd BufReadPre *.xml :set encoding=utf-16
"language message zh_CN.UTF-8
set fileencodings=ucs-bom,utf-16,uork/经典/客户/上海世纪/汉语新词典tf-8,cp936,gb18030,big5,euc-jp,sjis,euc-kr,ucs-2le,latin1
set awa
set ai
set showcmd
set nocompatible
set ruler
set acd " automatically change directory.
" 去掉烦人的编辑提示
set nobackup
set writebackup
set noswf " 去掉烦人的交换文件. 09/11/06 thinkhy
"set backupskip
" set isk="@,48-57,_,128-167,224-235,〗,〖" 这个设置没成功,暂不清楚原因。 09/11/20 thinkhy
" [Added by thinkhy 10/01/15]
" 不让会话文件所在的目录会成为当前目录,保证mksession后能正确打开文件
set ssop-=sesdir
" [Added by thinkhy 10/04/02]
" 文件补全时不做反斜扛替换
set shellslash
syntax enable
set cindent
inoremap <CR> <ESC>
inoremap <CR> <ESC>
nmap <Space> o<ESC>
nmap <F2> :w<CR>
imap <F2> <ESC>:w<CR>
nmap <F3> <C-w>w
imap <F3> <ESC><C-w>w
nmap <F4> <C-w>c
imap <F4> <ESC><C-w>c
" 改变窗口大小
map <Down> <ESC>:winc-<CR>
map <Up> <ESC>:winc+<CR>
map <Left> <ESC>:winc<<CR>
map <Right> <ESC>:winc><CR>
" 改变编辑窗口
map <M-k> <ESC><C-w>k
map <M-j> <ESC><C-w>j
map <M-n> <ESC><C-w>h
map <M-l> <ESC><C-w>l
" 在多个文件中grep当前光标下的单词 090323 thinkhy
" 加上java文件 [09/10/22 thinkhy]
" 加js文件 [09/01/19 thinkhy]
map gr :vimgrep <cword> *.cpp *.c *.h *.java *.js *.rc<CR>
map gR :vimgrep <cword> **/*.cpp **/*.c **/*.h *.java *.js *.rc<CR>
" map两个最常用的操作 系统剪贴板的复制粘贴[10/03/10 thinkhy]
nmap <c-k> "+p
vmap <c-k> "+p
imap <c-k> <c-r>+
noremap <c-y> "+y
" map <C-y> <ESC>"+ya
" 命令模式映射
" 1 建立C++工程的tags文件
" cmap ctags !ctags -R --kinds-c++ --fields=+iaS --extra=+q --language-force=c++
autocmd FileType c,cpp,h,xml,xsd,xsl :setlocal tabstop=4 expandtab
autocmd FileType c,cpp,h :let @g='vimgrep // *.c *.cpp *.h'
autocmd FileType xml :let @h='<?xml version="1.0" encoding="utf-8"?> '
autocmd FileType xml,html :nmap <F12> :%!xmllint --format %<CR>
autocmd FileType xml,html :imap <F12> <ESC>:%!xmllint --format %<CR>
" 书版 09/10/30 thinkhy
autocmd BufNewFile,BufRead *.fbd :syntax on runtime! syntax/fbd.vim
"au Syntax fbd runtime! syntax/fbd.vim
" 设置用于lookup插件的filetags
let g:LookupFile_TagExpr='"filenametags"'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Code Tags
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MFC tags And Windows API tags
autocmd FileType c,cc,cpp,h :setlocal tags+=d:/work/tags/mfc/tags
" wine 模拟windows内核代码
autocmd FileType c,cc,cpp,h :setlocal tags+=d:/work/tags/winapi/windows/tags
" XTP控件源代码
autocmd FileType c,cc,cpp,h :setlocal tags+=d:/work/tags/third_part/tags
autocmd FileType c,cc,cpp,h :setlocal path=.,D:/work/tags/mfc/include,D:/work/tags/winapi/Include_HY,D:/work/tags/third_part
" WEB代码直接
autocmd FileType javascript,html,htm :set tags+=d:/work/tags/WebKit/tags
"***************************************************************************
" For Plugin
"""""""""""""""""""""
" 1> Taglist
"""""""""""""""""""""
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
nmap <F8> :TlistToggle<CR>
imap <F8> <ESC>:TlistToggle<CR>
"""""""""""""""""""""
" 2> A
"""""""""""""""""""""
nmap <F7> :A<CR>
imap <F7> <ESC>:A<CR>
"""""""""""""""""""""
" 3> lookupfile
"""""""""""""""""""""
let g:LookupFile_MinPatLength = 3 " 最少输入3个字开始匹配
let g:LookupFile_PreserveLastPattern = 3 " 不保存上次查找的字符串
let g:LookupFile_PreservePatternHistory = 1 " 保存查找历史
let g:LookupFile_AlwaysAcceptFirst = 1 " 回车打开第一个匹配项目
let g:LookupFile_AllowNewFiles = 0 " 不允许创建不存在的文件
" lookup file with ignore case
function! LookupFile_IgnoreCaseFunc(pattern)
let _tags = &tags
try
let &tags = eval(g:LookupFile_TagExpr)
let newpattern = '/c' . a:pattern
let tags = taglist(newpattern)
catch
echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE
return ""
finally
let &tags = _tags
endtry
" Show the matches for what is typed so far.
let files = map(tags, 'v:val["filename"]')
return files
endfunction
let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""
" BufExplorer 09/07/18 在水木VIM版向flw收的技巧
"""""""""""""""""""""
nmap F :BufExplorer<CR>
"""""""""""""""""""""
" 4> miniBufexplore 这个插件不好用,暂时撤掉 09/11/26
"""""""""""""""""""""
" let g:miniBufExplMapWindowNavVim = 1
" let g:miniBufExplMapWindowNavArrows = 1
" let g:miniBufExplMapCTabSwitchBufs = 1
" let g:miniBufExplModSelTarget = 1
""""""""""""""""""""""""
" 发信人: SKPotti (冰封?晚饭无助), 信区: VIM
" 标 题: Re: 请问大家能用VIM打开附件中的文件吗?
" 发信站: 水木社区 (Wed Feb 3 12:10:39 2010), 站内
" fencview.vim
" 解决大部分的编码问题
" enc建议设成utf-8
" 感谢SKPotti,帮我解决了Windows里打开utf-8的问题
" 但utf-16的问题仍然没解决
" : FencAutoDetect
let g:fencview_autodetect = 1
"************************************************************************
" 在水木收的一些技巧
">=================================================
">=================================================
" [ 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 )
" 先拿下光标下的文字
let l:word = expand( "<cWORD>" )
" 再取出疑似函数名/模块名的部分和疑似方法的部分
" /([_a-zA-Z0-9:]/+/)/(->/([_a-zA-Z0-9]/+/)/)/?
let l:lists = matchlist( l:word, "//([_a-zA-Z0-9:]//+//)//(->//([_a-zA-Z0-9]//+//)//)//?" )
let l:name = l:lists[1]
let l:method = l:lists[3]
let l:progList = []
if &ft == "perl"
if match( l:name, "::" ) != -1
" 函数里是不可能有 :: 的,不用想了,一定是模块
let l:progList += [ [ "perldoc -u ", "pod" ] ]
elseif strlen( l:method )
" 有方法的,一定是模块了
let l:progList += [ [ "perldoc -u ", "pod" ] ]
elseif match( l:name, "[A-Z]" ) != -1
" 有大写字母,那一定是模块了,Perl buildin 函数的名称全都是小写字母的
let l:progList += [ [ "perldoc -u ", "pod" ] ]
else
" 剩下的,有可能是函数,也有可能是模块,
" 但是考虑到这样的模块较少,因此先优先查函数
let l:progList += [ [ "perldoc -u -f ", "pod" ], [ "perldoc -u ", "pod" ] ]
endif
endif
if &ft == "python"
let l: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"
if match( l:name, ":" ) != -1
" erlang 的模块方法
let l:lists = matchlist( l:name, "//([_a-zA-Z0-9:]//+//)://([_a-zA-Z0-9]//+//)" )
let l:name = l:lists[1]
let l:method = l:lists[2]
endif
let l:progList += [ [ "PAGER=/"col -b/" erl -man ", "man" ] ]
endif
let l:progList += [ [ "PAGER=/"col -b/" man 3 ", "man" ] ]
let l:progList += [ [ "PAGER=/"col -b/" man 2 ", "man" ] ]
let l:progList += [ [ "PAGER=/"col -b/" man ", "man" ] ]
let l:found = 0
" 下面调用外部命令,取帮助信息
" [Added by thinkhy 10/01/02]
if &ft == "vim"
echomsg "I am vim"
try
execute " h " . l:word
catch /foo/
endtry
execute "wincmd p"
return
endif
" [End thinkhy]
for l:prog in l:progList
let l:progName = l:prog[0]
let l:fileType = l:prog[1]
let l:cmd = l:progName . l:name
let l:lines = system( l:cmd )
if !v:shell_error
if a:where ==? "inNewTab"
tabe
elseif a:where ==? "Vertical"
rightbelow new
else
above new
endif
set buftype = nofile
set ts = 8
execute "set ft=" . l:fileType
call append( 0, split( l:lines, "/n" ) )
normal gg
if strlen(l:method) " 跳转到方法
if l:fileType == "pod"
" regex: /(=item/d*/s/+/)/@<= />
call search( "//(=item//d*//s//+//)//@<=" . l:method . "//>" )
elseif l:fileType == "man"
" regex: /(^/s/+/)/@<=l:method/>
call search( "//(^//s//+//)//@<=" . l:method . "//>" )
endif
endif
let l:found = 1
break
endif
endfor
if !l:found
echohl ErrorMsg | echomsg "^_^ 没有帮助信息。" | echohl None
endif
endfunction
" vim 内打开 man/perldoc/erl -man/python help
autocmd FileType c,perl,erlang,python,vim nmap <silent> K :call HelpHelper( "" )<CR>
autocmd FileType c,perl,erlang,python,vim nmap <silent> gK :call HelpHelper( "InNewTab" )<CR>