`
lovecontry
  • 浏览: 1033640 次
文章分类
社区版块
存档分类
最新评论

[技术学习]新年在水木VIM版所学总结

 
阅读更多

">=================================================
">=================================================
" [ 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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics