Vi keybindings for R command line like in Bash

老子叫甜甜 提交于 2019-12-03 15:48:28

问题


Context

I like editing and manipulating the bash command line using vi-style key bindings with the following setting:

set -o vi

However, when I start R on the command-line, these keybindings disappear. I know that the Vim-R plugin allows for Vim keybindings when you run R through the Conque Shell, but I'm not entirely happy with that experience, and, regardless, sometimes I just want to run R on the standard command-line.

Question

  • Is there any way of getting Vi style key bindings in R on the command line?

回答1:


Thank you to Joshua Ulrich and progo's answers, which helped to get me started.

Below I record my experience:

Initial setup

I tried set keymap vi and set editing-mode vi. When I started R in my Gnome Terminal, some shortcuts worked and others did not. In particular cc, and dd (i.e., delete lines) did not work at all, and cw and dw performed the action of deleting words but did not update the display until I pressed an additional key, which is not a functional experience.

Replacing missing functionality

  • I found this inputrc file that gave me a few ideas.
  • The help page was helpful, naturally.

I added the following to ~/.inputrc, which fixed the obvious problems mentioned above:

set completion-ignore-case on

set editing-mode vi

$if mode=vi
    set keymap vi-insert
    "\C-l": clear-screen
    "\C-p": history-search-backward
    "\C-n": history-search-forward
    # alt dot cycles through last argument
    "\e.":yank-last-arg

    set keymap vi-command
    "D":kill-line
    "dw": kill-word
    "dd": kill-whole-line
    "db": backward-kill-word
    "cc": "ddi"
    "cw": "dwi"
    "cb": "dbi"
    "diw": "lbdw"
    "yiw": "lbyw"
    "ciw": "lbcw"
    "diW": "lBdW"
    "yiW": "lByW"
    "ciW": "lBcW"
    "gg": beginning-of-history
    "G": end-of-history
$endif



回答2:


Add this to your .inputrc:

set editing-mode vi



回答3:


The R commandline seems to use Readline. Readline uses .inputrc for settings:

set keymap vi

to your ~/.inputrc.



来源:https://stackoverflow.com/questions/6235034/vi-keybindings-for-r-command-line-like-in-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!