A trick for keywordprg
Scouting web for what's possible with git aliases, I have found a cool trick on how to combine/chain calls to several tools when the program allows to configure only one. The trick turned out to be not new, but more of the old, forgotten ones: define one-shot shell function.
Example. How to make perl's keyword program to look into both functions and module helps.
Old one, looking only for function's help:
au BufReadPost *.pl set keywordprg=perldoc\ -f
The trick in action:
au BufReadPost *.pl set keywordprg=f(){\ perldoc\ -f\ $*\|\|perldoc\ $*;};f
Deescaped command looks like that: f(){ perldoc -f $* || perldoc $*; }; f
VIM would append the word to search for at the end and run it. Shell would see pretty normal function definition and immediately after a call to it.
The trick obviously works only on the platforms which have Bourne shell.
No comments:
Post a Comment