[vox-tech] vi key bindings, readline and bash

Peter Jay Salzman vox-tech@lists.lugod.org
Sun, 30 Mar 2003 13:51:27 -0800


solved by donald j. bindner who was kind enough to respond to a post i
made to comp.unix.questions ... god knows how long ago.   a year?  two
years maybe?

as i suspected, the problem is that debian testing and unstable have
newer versions of readline than suse, redhat or debian stable (the three
platforms his key bindings worked under).

donald figured out that the new readline now uses a timing feature to
help it distinguish between an escape character and an escape character
than occurs as part of a keycode (like the F1 key).   he wrote the
following bindings.

basically, you're in emacs mode unless you press escape.  then you're in
vi mode.  this is nice because you have powerful and short vi commands
yet still have the emacs conveniences like "up arrow" instead of typing
"escape up arrow".

here's don's readline bindings:



## .bash_bindings: source this file from your .bashrc or .bash_profile
#
# For those who want to use Vi bindings in bash, this corrects a
# few annoyances:
#
# 1) up and down arrows retrieve history lines even in insert mode
# 2) left and right arrows work in insert mode
# 3) Ctrl-A and Ctrl-E work how you expect if you have had to
#    live in Emacs mode in the past.
# 4) So does Ctrl-D.

## Command-mode bindings
# Ctrl-A or Home: insert at line beginning like in emacs mode
 bind -m vi-command 'Control-a: vi-insert-beg'
# Ctrl-E or End: append at line end like in emacs mode
 bind -m vi-command 'Control-e: vi-append-eol'
# to switch to emacs editing mode
 bind -m vi-command '"ZZ": emacs-editing-mode'

## Insert-mode bindings
# up arrow or PgUp: append to previous history line
 bind -m vi-insert '"\M-[A": "=10=05"'
 bind -m vi-insert '"\M-[5~": "=10=05"'
 bind -m vi-insert 'Control-p: previous-history'
# dn arrow or PgDn: append to next history line
 bind -m vi-insert '"\M-[B": "=10=05"'
 bind -m vi-insert '"\M-[6~": "=10=05"'
 bind -m vi-insert 'Control-n: next-history'
# Ctrl-A: insert at line start like in emacs mode
 bind -m vi-insert 'Control-a: beginning-of-line'
# Ctrl-E: append at line end like in emacs mode
 bind -m vi-insert 'Control-e: end-of-line'
# Ctrl-D: delete character
 bind -m vi-insert 'Control-d: delete-char'
# Ctrl-L: clear screen
 bind -m vi-insert 'Control-l: clear-screen'

## Emacs bindings
# Meta-V: go back to vi editing
 bind -m emacs '"\ev": vi-editing-mode'

## Specify vi editing mode
 set -o vi




begin Charles Polisher <cpolish@attbi.com>=20
> Peter Jay Salzman wrote:
> > begin Charles Polisher <cpolish@attbi.com>=20
> > > Peter Jay Salzman wrote:
> > > > chuck,
> > > >=20
> > > > is your libreadline 4.2 or 4.3?    every 4.2 system i've tried, it
> > > > works.
> > > >=20
> > > > it doesn't seem to work on 4.3.
> > >=20
> > > I locate'd this file: /lib/libreadline.so.4.2
> > > so I guess it's 4.2...
> > >=20
> > > Could it be something to do with $TERM ? Mine's
> > > set to "xterm", but iirc sometimes people use
> > > "linux" or some such. ?
> >=20
> > i used to set mine to linux, but switched over to xterm awhile ago.
> >=20
> > hrmmm... i think perhpas it's time to post a question to bug-readline.
> >=20
> > thanks, chuck.  i appreciate you putting up with my questions.  :)
>=20
> I'm always pleased if I can help,
>=20
>=20
> Chuck
> --=20
> Object-oriented programming is an exceptionally bad idea which
> could only have originated in California.    --Edsger Dijkstra

--=20
Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D