Hi;
On and off for the last few years I have tried to get readline to bind commands as I want them but they never have. I am sure I am doing something stupid or mis-interpreting the manuals and all the previous advice I have received. I posted this problem over a week ago on the Fedora Forum but got nothing helpful. So here -- slowly -- is my problem.
I can find "\e-f": forward-word and "\e-b": backward-word in /etc/inputrc and they work.
However, I find the \e- key combination a bit of a finger reach and I use forward-word and backward-word a lot so I wanted to add a key modifier combination that was easier. I have tried several different versions of key binding in ~/.inputrc but nothing seems to work. Here is the latest version of my ~/.inputrc:
# Bill's inputrc for ReadLine
# '$include' directs readline to the file # with 'universal' settings.
$include /etc/inputrc
$if mode=emacs
"\M-\C-b": backward-word "\M-\C-f": forward-word
$endif
As I say, I have tried several different versions e.g "\M-\C-b": and "\M-\C-f: but nothing works. Even after using C-xC-r or rebooting. (I am familiar with emacs bindings.) _______________
I have checked that the emacs mode is on:
]$ env ... VISUAL=emacs GIT_EDITOR=emacs ....
]$ set -o (which tells me ) ... emacs on ... vi off.
So the mode=emacs has nothing to do with the key binding problem I am having. ________________
For the above file:
]$ bind -P ... backward-word can be found on "\eOd", "\e[1;5D", "\e[5D", "\eb", "\202", ... ... forward-word can be found on "\eOc", "\e[1;5C", "\e[5C", "\ef", "\206".
... __________________
Where do "\202" and "\206" come from and what are they. While we are at it, where can I find a meaningful translation of "\eOd", "\e[1;5D", "\e[5D", etc. I know what \e is but what do [, O, 1 mean? How could I find them on a keyboard?
I have tried: ]$ bind "\C-\M-b": backward-word and ]$ bind "\C-\M-f": forward-word
to no effect. ___________________
Meta (ALT) -b works (does backward-word) for some reason (as in /etc/inputrc) but \M-\C-b doesn't. Meta (ALT) -f gives me the window menu, as it should. I don't want to change that. But ~/.inputrc gives me nothing with ALT(Meta)-CTRL-f. I was kind of hoping to figure out how to substitute \M-\C- for all or many of the "\e" bindings on my local or users .inputrc.
Currently ]$ env doesn't show INPUTRC which should be the correct default.
In case it is helpful, my ~/.bash_profile contains # export INPUTRC= $HOME/.inputrc [commented out #, and in at different times].
I am currently using Fedora 12 kernel version 2.6.32.9-67.fc12.x86_64.; but as I said I haven't been able to figure this out over several versions. Others don't seem to be having any problem at all. I would deeply appreciate it if someone could help me sort this out.
I am sure that the problem comes from my doing something silly or from staring at it too long, or making it more complex than it really is; but for now I am stumped.
On Thu, Mar 11, 2010 at 01:37:29PM -0500, William Case wrote:
"\M-\C-b": backward-word "\M-\C-f": forward-word
As I say, I have tried several different versions e.g "\M-\C-b": and "\M-\C-f: but nothing works. Even after using C-xC-r or rebooting. (I am familiar with emacs bindings.)
In my setup Meta-Control-B sends a two character sequence of ESC ^B.
The following seems to work:
"\e\C-b": backward-word
You can verify what your own setup does by pressing ^V (or just use cat) and pressing meta-control-b to see what the terminal is sending.
me
On Thu, 2010-03-11 at 12:58 -0800, Michael Elkins wrote:
On Thu, Mar 11, 2010 at 01:37:29PM -0500, William Case wrote:
"\M-\C-b": backward-word "\M-\C-f": forward-word
As I say, I have tried several different versions e.g "\M-\C-b": and "\M-\C-f: but nothing works. Even after using C-xC-r or rebooting. (I am familiar with emacs bindings.)
In my setup Meta-Control-B sends a two character sequence of ESC ^B.
The following seems to work:
"\e\C-b": backward-word
You can verify what your own setup does by pressing ^V (or just use cat) and pressing meta-control-b to see what the terminal is sending.
]$ ^V then Alt-Ctrl+b returns "^[" cat returns nothing.
On Thu, 11 Mar 2010 18:41:41 -0500 William Case wrote:
]$ ^V then Alt-Ctrl+b returns "^[" cat returns nothing.
Speaking of what the terminal is sending, I have indeed often been confused by "helpful" terminal apps and distro modified default configs that cause the terminal apps to send totally wacky nonsense when some key is pressed (as near as I can tell because that was the personal preference of the maintainer and therefore everyone should benefit from his preferences being the dedault). Often keys you are absolutely certain will send one thing actually send something else. I don't know if it explains any of your problems, but it has certainly caused me to waste lots of time in the past.
On Thu, 2010-03-11 at 18:41 -0500, William Case wrote:
On Thu, 2010-03-11 at 12:58 -0800, Michael Elkins wrote:
On Thu, Mar 11, 2010 at 01:37:29PM -0500, William Case wrote:
"\M-\C-b": backward-word "\M-\C-f": forward-word
As I say, I have tried several different versions e.g "\M-\C-b": and "\M-\C-f: but nothing works. Even after using C-xC-r or rebooting. (I am familiar with emacs bindings.)
In my setup Meta-Control-B sends a two character sequence of ESC ^B.
The following seems to work:
"\e\C-b": backward-word
You can verify what your own setup does by pressing ^V (or just use cat) and pressing meta-control-b to see what the terminal is sending.
]$ ^V then Alt-Ctrl+b returns "^[" cat returns nothing.
Sorry Michael:
]$ cat -v ^[^B^C
When input cat -v [Enter] then Alt-Ctrl+b
On Thu, 2010-03-11 at 19:02 -0500, William Case wrote:
On Thu, 2010-03-11 at 18:41 -0500, William Case wrote:
On Thu, 2010-03-11 at 12:58 -0800, Michael Elkins wrote:
On Thu, Mar 11, 2010 at 01:37:29PM -0500, William Case wrote:
"\M-\C-b": backward-word "\M-\C-f": forward-word
As I say, I have tried several different versions e.g "\M-\C-b": and "\M-\C-f: but nothing works. Even after using C-xC-r or rebooting. (I am familiar with emacs bindings.)
In my setup Meta-Control-B sends a two character sequence of ESC ^B.
The following seems to work:
"\e\C-b": backward-word
You can verify what your own setup does by pressing ^V (or just use cat) and pressing meta-control-b to see what the terminal is sending.
]$ ^V then Alt-Ctrl+b returns "^[" cat returns nothing.
Sorry Michael:
Typo Fix
]$ cat -v ^[^B
When input cat -v [Enter] then Alt-Ctrl+b
On Thu, Mar 11, 2010 at 07:02:20PM -0500, William Case wrote:
On Thu, 2010-03-11 at 18:41 -0500, William Case wrote:
On Thu, 2010-03-11 at 12:58 -0800, Michael Elkins wrote:
You can verify what your own setup does by pressing ^V (or just use cat) and pressing meta-control-b to see what the terminal is sending.
]$ ^V then Alt-Ctrl+b returns "^[" cat returns nothing.
Sorry Michael:
]$ cat -v ^[^B^C
When input cat -v [Enter] then Alt-Ctrl+b
Yes, so you get the same behavior as my setup where Alt-Ctrl-B ends up sending ESC followed by Ctrl-B (the Ctrl-C is just from you exiting the program). You should be able to bind to "\e\C-b" just like I was.
The Ctrl-V trick didn't work because it only echos back the next character. Since Alt-Ctrl-B is returning two keys, it only shows the next one, and then bash is getting the ^B,
me
On Thu, 2010-03-11 at 16:07 -0800, Michael Elkins wrote:
On Thu, Mar 11, 2010 at 07:02:20PM -0500, William Case wrote:
On Thu, 2010-03-11 at 18:41 -0500, William Case wrote:
On Thu, 2010-03-11 at 12:58 -0800, Michael Elkins wrote:
You can verify what your own setup does by pressing ^V (or just use cat) and pressing meta-control-b to see what the terminal is sending.
]$ ^V then Alt-Ctrl+b returns "^[" cat returns nothing.
Sorry Michael:
]$ cat -v ^[^B^C
When input cat -v [Enter] then Alt-Ctrl+b
Yes, so you get the same behavior as my setup where Alt-Ctrl-B ends up sending ESC followed by Ctrl-B (the Ctrl-C is just from you exiting the program). You should be able to bind to "\e\C-b" just like I was.
The Ctrl-V trick didn't work because it only echos back the next character. Since Alt-Ctrl-B is returning two keys, it only shows the next one, and then bash is getting the ^B,
So ...
]$ bind "\e\C-b": backward-word
Tried it on a several word command line from History. No motion.
On Thu, Mar 11, 2010 at 07:18:28PM -0500, William Case wrote:
]$ bind "\e\C-b": backward-word
Tried it on a several word command line from History. No motion.
Because of the peculiarities of shell quoting, you need to quote the key sequence inside single quotes because the double quotes are significant to bind
bind '"\e\C-b"':backward-word
Also note the lack of space around the colon when using the 'bind' command as opposed to putting it in ~/.inputrc.
me
Hi; On Thu, 2010-03-11 at 16:42 -0800, Michael Elkins wrote:
On Thu, Mar 11, 2010 at 07:18:28PM -0500, William Case wrote:
]$ bind "\e\C-b": backward-word
Tried it on a several word command line from History. No motion.
Because of the peculiarities of shell quoting, you need to quote the key sequence inside single quotes because the double quotes are significant to bind
bind '"\e\C-b"':backward-word
Also note the lack of space around the colon when using the 'bind' command as opposed to putting it in ~/.inputrc.
An explanation or example with the man bash bind command would be helpful !!
Did it. Got it. The '"\e\C-b"':backward-word binding works.
Now the question is, how do I set it up in my .inputrc? Just try "\e \C-b": backward-word ? Or \e^B ?
How can I test that readline is even reading my .inputrc?
On Thu, Mar 11, 2010 at 08:15:43PM -0500, William Case wrote:
Now the question is, how do I set it up in my .inputrc? Just try "\e \C-b": backward-word ? Or \e^B ?
Just put the following line in your ~/.inputrc:
"\e\C-b": backward-word
The man page says the colon *must not* have a space after the key sequence.
How can I test that readline is even reading my .inputrc?
$ bind -P | grep backward-word
You should see something like:
backward-word can be found on "\e\C-b", "\eb".
Note the addition of the new key binding to the stock binding of M-b.
me
Thank you Michael;
I have saved the remarks that you sent me for future use. The whole solution was contained in those notes.
For those who maybe having similar problems.
On Thu, 2010-03-11 at 13:37 -0500, William Case wrote:
Hi;
On and off for the last few years I have tried to get readline to bind commands as I want them but they never have. I am sure I am doing something stupid or mis-interpreting the manuals and all the previous advice I have received. I posted this problem over a week ago on the Fedora Forum but got nothing helpful. So here -- slowly -- is my problem.
Ultimately the answer was to substitute \e for \M in the 'bind' command and/or .inputrc. Strictly following the bash quotation rules as pointed out got the 'bind' command working.
However, and perhaps defensively, I have to blame the bash manual description for my difficulties. Nowhere is there a suggestion that \e might be substituted for \M, if \M (Alt) isn't working as the Meta key. \M (Alt) does work as the Meta key in my Emacs. In fact, all the examples and cursory explanations lead one away from the e\ solution and all the sites that I googled were substantially a repeat of the manual.
There is no explanation of what key strokes mean e.g. a meaningful translation of "\eOd", "\e[1;5D", "\e[5D", etc. or a link or a suggested site to find further information. As a result I had no inkling of what the key bindings as shown in /etc/inputrc were.
Reference to Emacs is misleading in this context. Yes I understand what emacs mode is, but as used in the manual I fully expected to be able to use and/or create emacs bindings that are familiar to me. None worked.
Thank you for the introduction to the ^V key sequence. Where would I find a manual description of its use? cat -v I had never used before and had to look it up in man cat. It will remain part of my command repertoire.
On Thu, Mar 11, 2010 at 10:12:59PM -0500, William Case wrote:
However, and perhaps defensively, I have to blame the bash manual description for my difficulties. Nowhere is there a suggestion that \e might be substituted for \M, if \M (Alt) isn't working as the Meta key. \M (Alt) does work as the Meta key in my Emacs. In fact, all the examples and cursory explanations lead one away from the e\ solution and all the sites that I googled were substantially a repeat of the manual.
This is from the "Readline Notation" section of the bash(1) man page:
In this section, the emacs-style notation is used to denote keystrokes. Control keys are denoted by C-key, e.g., C-n means Control-N. Simi larly, meta keys are denoted by M-key, so M-x means Meta-X. (On key boards without a meta key, M-x means ESC x, i.e., press the Escape key then the x key. This makes ESC the meta prefix. The combination M-C-x means ESC-Control-x, or press the Escape key then hold the Control key while pressing the x key.)
There is no explanation of what key strokes mean e.g. a meaningful translation of "\eOd", "\e[1;5D", "\e[5D", etc. or a link or a suggested site to find further information. As a result I had no inkling of what the key bindings as shown in /etc/inputrc were.
Yes, this is particularly tricky. Most of the time you don't need to worry about which key sequences your particular terminal is sending because of the use of libraries like termcap or curses which hide the differences. If you are interested in the details you are looking for either ANSI or VT100 escape sequences. Here's one link that details the sequences (you'll have to do a bit more searching if you want a textual explanation).
http://ascii-table.com/ansi-escape-sequences-vt-100.php
Thank you for the introduction to the ^V key sequence. Where would I find a manual description of its use? cat -v I had never used before and had to look it up in man cat. It will remain part of my command repertoire.
Quoting from the bash(1) man page:
quoted-insert (C-q, C-v) Add the next character typed to the line verbatim. This is how to insert characters like C-q, for example.
me