When we talk about commandline manipulation we're really talking about the readline library. Updating the readline bindings can be done from the commandline as in your example, in the main init file for readline
/etc/inputrc (check this with
echo $INPUTRC), or create a local init for your account
~/.inputrc. If you haven't already lookup GNU readline library (try here)
Having said that, here are some suggestions for your problem:
- zsh uses readline and you could likely inspect the key binding for ESC-h (
\eh) under an account with zsh and copy that binding into your account with bash. Some really smart people have put those bindings together and it may work without any tweaking.
- In a zsh account use the bind command (
bind -P [use the lowercase p switch for raw binding output]) to view the active bindings in a zsh account.
- You may need to piece together the actual codes from the output of bind.
- Add the complete line to your bindings in your bash account (like you tried to do above)
- Follow the path in your example above
On that note your example above could work, but it needs a little tweaking. This worked for me
"\eh": "\C-a\C-kman \e1\e.\C-m\C-y\M-y"
I put my binding in /etc/inputrc. You must re-read inputrc at the commandline using the key sequence
However, your question is how to do this for the word under the cursor. This worked for me:
"\eh": "\ef\eb\ed\C-y\e#man \C-y\C-m\C-p\C-p\C-a\C-d"
In short, it works like this:
For the key sequence
- first find the end of the word, then the beginning (
- delete the current word (the one your interested in) and put it back (
\ed\C-y). We need to get it in the kill buffer.
- comment out the entire commandline and go to a new prompt (
- type "man " on the commandline (notice the space)
- paste your command of interest on the commandline and execute it (
- find the second (previous) entry in the command history ("man" and then you original command) (
- go to the beginning of the line and delete the comment char (
- Set readline to use emacs and vi mode. You may be able to use use most of your favorite, and very powerful editor commands in your keybindings.
Note: I have not tried implementing this option as a binding before, but I do use it at the commandline. You can set this via the inputrc file, or bashrc.
- In inputrc:
set editing-mode vi
- In bashrc:
set -o vi
The process of doing the binding is the seems similar to the default readline key sequences. But the examples in suggestion 2 should put you on the right path.