">=================================================
">=================================================
" [ 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>
">==========================================================================
"发信人: Dieken (风催草低 - 明月何尝不照人), 信区: VIM
"标 题: Re: 分享几个我自认为比较得意的自定义快捷键
"发信站: 水木社区 (Mon Dec 28 12:00:38 2009), 站内
" 我也来:
" Press v in quickfix window to preview
" 虽然没看懂zz:的意思,好使
au FileType qf :nnoremap <buffer> v <Enter>zz:wincmd p<Enter>
" for gf command to open java source file at import clause
au FileType java :set suffixesadd+=.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>