Keyboard shortcuts in the R console in OS terminal

Sometimes I use the R console in the operating system terminal (i.e., by typing "R" in a Linux or MacOS terminal, or "R.exe" in DOS, etc.).

In that console, keyboard shortcuts that work in the RStudio console and RStudio editor no longer work. That, of course, is to be expected.

But what do I have to do to some keyboard shortcuts to work? For example, if I just wanted "ALT + -" to enter in " <- " just like it does in RStudio, what are my options?

In case it makes a difference, I am particularly interested in getting this working in a Linux terminal (I usually use Kitty) where my shell is zsh.

This sounds like a zsh question, so you might want to post it on Stack Exchange's Unix/Linux site, too:

My guess is you'll have to add the appropriate code to your .zshrc file, which controls the default behavior of zsh, but I'm not sure what they would be.

1 Like

If the only or best solution is to a key mapping in .zshrc, then it would be something like

bindkey -s '\e-' ' <- '

where the \e stands for ALT, so \e- means ALT+-.

I suppose my question should have been more specific then. I should have asked more specifically whether this keymapping can be done in some R startup files, or whether it needs to be done in your shell startup files, or elsewhere.

I see — thanks for the clarification, @mjandrews.

I'm not aware of any way to modify key bindings within R itself, but maybe others are. However, from my own attempts to modify key bindings, my impression is that key bindings are interpreted by the active window, which can either use or override OS-level key bindings. So that if invoked in a terminal, R would rely on the terminal's key bindings since it's not responsible for the window. Maybe R GUI would allow it, if that were an acceptable alternative?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.