1

I've created some custom key bindings for bash vi mode. They trigger while I'm in insert mode and I want them instead to trigger when I'm in normal mode.

I'm using vi mode

set -o vi

in a terminal emulator on Ubuntu 14.04 server. So far I have remapped:

^ — Move to start of line

$ — Move to end of line

To the following:

<space>a — Move to start of line

<space>; — Move to end of line

Using the bash built-in command bind by editing .bashrc as follows:

bind " -a":beginning-of-line
bind " -;":end-of-line

These key bindings work - but they only trigger when I'm in insert mode. How do I get them only to fire only when I'm in normal mode and not in insert mode, instead?

tags: bash vi mode, bash vi mode remap keys, vi mode normal mode

  • How would you expect the interface to be able to determine when <space>a is intended to send the cursor to the start of the line rather than a literal space followed by an a? – DopeGhoti May 31 '16 at 6:02
  • @DopeGhoti It does this already, though not perfectly. The bindings shown work correctly - though pressing the spacebar in normal mode and insert mode advances the cursor by default - it doesn't matter in this case because you'll still end up at either the beginning or end of the line as intended. – user3751385 May 31 '16 at 6:07
  • 1
    You should remap those in ~/.inputrc and you can then distinguish between vi-command and vi-insert. – jasonwryan May 31 '16 at 6:25
  • @jasonwryan You're right. I just saw that on the vim wiki vim.wikia.com/wiki/Use_vi_shortcuts_in_terminal. Thanks. – user3751385 May 31 '16 at 6:41
1

This is how its done in .inputrc:

set editing-mode vi
$if mode=vi

# these are for vi-command mode
set keymap vi-command

# unbind space
" ": ""

# bind space-a, space-;
" a":beginning-of-line
" ;":"$" 

$endif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.