When using vi mode (set -o vi) with Bash, is it possible to remap the cursor keys to so that they don't work (and be forced to use h, j, k and l movement keys)?

Under vim (the editor), I can do it with:

noremap <Up> <nop>
noremap <Down> <nop>
noremap <Left> <nop>
noremap <Right> <nop>

But I don't know how to do it in readline's vi mode.

1 Answer 1


You can edit your .inputrc file as follows:

$if mode=vi

It will map the arrow key to nothing.

  • Tested in both .inputrc and /etc/inputrc (and starting a new SSH session) and the cursors still work... Any idea? EDIT: Ok, doing "bind -f .inputrc" it's partially working. It blocks the cursors in INSERT MODE but not in COMMAND MODE. It could be enough for me, thanks! I don't know why .inputrc is not read on each login :-?
    – sromero
    Commented Apr 17, 2015 at 14:30
  • And when you call them like this: bind '"\eOD":""' in a running session?
    – chaos
    Commented Apr 17, 2015 at 14:31
  • No, that does not work. It only works in the .inputrc file and using the "bind -f .inputrc" command ...
    – sromero
    Commented Apr 17, 2015 at 14:40
  • @sromero I would recommend to add set -o vi followed by bind -f .inputrc into your .bashrc to make it permanent.
    – chaos
    Commented Apr 17, 2015 at 14:48
  • Ok, thanks. If nobody gives the full answer (block arrow keys in command mode too) I'll set your answer as the accepted one (it solved half of the problem! :).
    – sromero
    Commented Apr 17, 2015 at 14:57

You must log in to answer this question.

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