在inputrc(readline)中将jj映射到Esc

32

我该如何在inputrc中将jj映射到Esc,以便它可以被使用GNU Readline的应用程序(如python、mongoshell等)识别出来?

在zsh上使用以下代码一切正常:

bindkey -M viins 'jj' vi-cmd-mode

这是我的当前inputrc:

set editing-mode vi
set keymap vi

# turn off the stupid bell
set bell-style none
$if mode=vi
    set keymap vi-command
    "gg": beginning-of-history
    "G": end-of-history
    #"jj": vi-movement-mode
    set keymap vi-insert
    "\C-w": backward-kill-word
    "\C-p": history-search-backward
$endif

感谢提供 zsh 命令行,它让我开始设置 vim/emacs 混合 readline。 - Ehtesh Choudhury
1个回答

30

你应该重新排列inputrc文件,以便注释的行在set keymap vi-insert行之后。

像这样:

set bell-style none
$if mode=vi
    set keymap vi-command
    "gg": beginning-of-history
    "G": end-of-history
    set keymap vi-insert       #notice how the "jj" movement is
    "jj": vi-movement-mode     #after 'set keymap vi-insert'?
    "\C-w": backward-kill-word
    "\C-p": history-search-backward
$endif

2
要了解适用于插入模式和命令模式的内容,请参考此答案:http://superuser.com/questions/286781/readline-difference-between-vi-vi-move-vi-command-vi-insert-keymaps - Michael Scheper
有没有可能为<C-c>做类似的事情?我习惯在vim中使用它,退出插入模式比换行更好。最好不要在进程运行时改变控制-C功能。(顺便说一下,我目前正在使用bash) - mrfred

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接