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

4
  • 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, 2016 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. May 31, 2016 at 6:07
  • 1
    You should remap those in ~/.inputrc and you can then distinguish between vi-command and vi-insert.
    – jasonwryan
    May 31, 2016 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. May 31, 2016 at 6:41

1 Answer 1

2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .