l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Jun 13 13:19

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] readline questions (in bash)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] readline questions (in bash)

hi all,

it took me about 3 years of searching to find the answer to this.

i can't remember the guy's name who wrote this, but i've found the
results to be very, very satisfactory.  i'm quite pleased with these

basically, you're in emacs mode, so ^w, ^e, ^a, ^u work, as do up/down
arrow keys.

once you press escape, you're in vi command mode.  however, the arrow
keys actually work!  another annoyance with vi mode was that ^l didn't
work either without pressing escape first.  that's fixed by these
bindings as well.

i put all this in a file /etc/skell/.bash_bindings and ~/.bash_bindings.
then i source it everytime an interactive shell is started.


## .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.
# 5) And Ctrl-L.

## 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": ""'
 bind -m vi-insert '"\M-[5~": ""'
 bind -m vi-insert 'Control-p: previous-history'
# dn arrow or PgDn: append to next history line
 bind -m vi-insert '"\M-[B": ""'
 bind -m vi-insert '"\M-[6~": ""'
 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
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.