I am using the vim mode in my bash (i.e. I setup readline to use vim mode through ~/.inputrc).

If I do a history-search-backward and then history-search-forward in insert mode with some characters already typed, the bash jumps to command mode when the forward-search arrives at the end.

For example, this happens when I:

  • Type echo "foo"
  • Type e
  • Press Up Arrow (prompt shows echo "foo" in insert mode)
  • Press Down Arrow (prompt shows echo "foo" in command mode)

It does not happen if I omit the step where I type e.

Furthermore, bash also jumps to command mode whenever I press the Delete key, plus it toggles capitalization.

For example, this happens when I:

  • Type echi
  • Move left
  • Press Delete (prompt shows ecHi in command mode)

This happens independent of moving left, only the letter that is toggled changes.

(The first phenomenon occurs exactly the same way in ipython, which also uses readline. The second phenomenon is a bit diferent in ipython: Pressing delete in command mode does what it's supposed to do, pressing delete in insert mode also does what it's supposed to do, unless I am at the end of the line, in which case it also jumps back to command mode, but does not toggle capitalization.)

EDIT To fix the problem with the Delete key, put "\e[3~": delete-char in your '~/.inputrc`

I am using the following .inputrc:

  1 set editing-mode vi
  2 set keymap vi-command
  3 "\e[A":history-search-backward
  4 "\e[B":history-search-forward
  5 "\e[C":forward-char
  6 "\e[D":backward-char
  7 ##
  8 "j":history-search-forward
  9 "k":history-search-backward
 10 set keymap vi-insert
 11 "\e[A":history-search-backward
 12 "\e[B":history-search-forward
 13 "\e[C":forward-char
 14 "\e[D":backward-char
 15 ##
 16 set show-mode-in-prompt on
 17 ##
 18 set vi-cmd-mode-string "\1\e[2 q\2\1\e[1;31m\2(cmd)\1\e[0m\2"
 19 set vi-ins-mode-string "\1\e[5 q\2(ins)"
 20 ##
 21 set keymap vi-insert
 22 RETURN "\e\n"
 23 set keymap vi-command
 24 v: ""

and the following .vimrc:

filetype plugin on
set shellslash
set grepprg=grep\ -nH\ $*
filetype indent on
let g:tex_flavor='latex'
set ff=unix
nmap <CR> o<Esc>
set number
set showcmd
  • Use cat or Ctrl-V to see what the keys are actually sending - maybe there's an extra escape in there somewhere? – muru Aug 17 '17 at 8:25
  • @muru Delete is sending ^[[3~ – Bananach Aug 17 '17 at 8:26
  • I don't really understand what this means, but I do know that tilde toggles case in vim. So you seem to be up to something – Bananach Aug 17 '17 at 8:27
  • So you need to bing \e[3~ in readline to the delete function, whatever it maybe called. I'm removing the vim tag, since the vi mode in readline is not actually using vi or Vim, but is a partial re-implementation of some functionality present in vi. – muru Aug 17 '17 at 8:31
  • @muru "\e[3~": delete-char Thanks a lot. That solves one problem. Any idea about the other? – Bananach Aug 17 '17 at 8:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.