0

Is there a way to emulate Vim's 'imap' functionality in bash?

For example, in Vim I use imap jj <ESC> and imap kk <TAB> as convenience shortcuts. For those who don't use Vim, it means that when you type jj in short succession, it would be the equivalent of hitting escape.

The benefit is two very commonly used keystrokes easily accessible from the home row.

I realize there's a way in bash to bind existing keys, or combinations of keys to something else... but is there a way to bind sequences of keys pressed separately?

  • 1
    Is http://stackoverflow.com/questions/6839006/map-jj-to-esc-in-inputrc-readline an answer to your question? ("readline" is the library bash uses to handle keyboard interaction). – Charles Duffy Jul 03 '14 at 00:56
  • 1
    Have a look at the bash `man` page (`man bash`), around line 1755 or so, search for `inputrc`. You probably could set up keys as you wish. (Of course, __bookkeeper__ is going to be hard to type in bash though) – lornix Jul 03 '14 at 01:20
  • 1
    @CharlesDuffy Awesome, thanks. Using the inputrc in http://stackoverflow.com/questions/6839006/map-jj-to-esc-in-inputrc-readline plus adding "kk": "\t" to the keymap for vi-insert worked great. – DavidBettis Jul 03 '14 at 01:30
  • @user3799553, glad to hear that helped; I've tried to extract the relevant part as an answer. – Charles Duffy Jul 03 '14 at 03:25

1 Answers1

0

You can use the file ~/.inputrc to configure the readline library, which bash uses for handling input.

Consider something akin to the following:

$if mode=vi
    set keymap vi-insert
    "kk": "\t"
$endif

See map jj to Esc in inputrc (readline) for a more complete example.

Community
  • 1
  • 1
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441