Open maxheld83 opened 3 years ago
Is there a better way to identify whether you're currently "in an R project", other than
"when": "editorLangId == r || editorLangId == rmd"
?
Maybe when there's a DESCRIPTION
at project root?
Is there already such a facility inside vscode-R?
editorLangId == r || editorLangId == rmd && editorTextFocus"
doesn't quite create the RStudio experience. Whenever you're in a terminal (no way of knowing whether it's running radian at any point), or one of the non-R files (say, DESCRIPTION
, README.md
, ...) these keybindings won't fire.
Is there a better way to identify whether you're currently "in an R project", other than
"when": "editorLangId == r || editorLangId == rmd"
?
It's possible to set arbitrary context values from within the extension. This is done e.g. to only show help panel related navigation buttons when the active panel is actually an R help panel. See e.g. https://github.com/Ikuyadeu/vscode-R/blob/39f5914d691a3befb04768e4df33b7f83978fd44/package.json#L709 https://github.com/Ikuyadeu/vscode-R/blob/39f5914d691a3befb04768e4df33b7f83978fd44/src/rHelpPanel.ts#L113 https://code.visualstudio.com/api/references/when-clause-contexts#add-a-custom-when-clause-context
This could be used to e.g. set a context value r.isRProject
that is true whenever we identify the current project as an R project, or r.terminalIsR
to indicate that the currently active terminal window is one opened by the extension.
I found this issue because I fell for an unexpected key mapping collision: in RStudio, Ctrl+Shift+S runs the source, while that combination in VS Code (and many other tools, compare https://defkey.com/what-means/ctrl-shift-s) is usually used for "File - Save As". So instead of re-saving my file, I accidentally ran some R code in VS Code due to https://github.com/Ikuyadeu/vscode-R/blob/abd2392d7ef02ea5151b26004368fdedfcc979f4/package.json#L651-L656
In general, I am not sure it is beneficial to emulate RStudio behavior at all. RStudio is only for people working (mostly) with R. VS Code is not only for people who mostly use R, but people also use JavaScript, Python, etc. - often several languages across the same project. So I think I would put more focus on being consistent within the VS Code environment rather than compatibility with RStudio. Please consider that if and when revising any keyboard shortcuts (including Ctrl+Shift+S). It's easy for me to unmap*, but new users will always fall for that.
*How? Put this in your keybindings.json
:
{
"key": "ctrl+shift+s",
"command": "-r.runSource",
"when": "editorTextFocus && editorLangId == 'r'"
},
@bersbersbers cogently make a point I too arrived at after at first being delighted to find emacs keybinding emulation and then throwing up my hands in frustration as I found they introduced conflicts with other things I wanted, including the ability to follow along others' VS Code tutorials & recipes that were given in terms of standard bindings.
Of course, TIMTOWTDI.
Or, À chacun son goût.
Or YMMV.
For me, I'm hoping if/when notebooks allow mixing cells between different languages/kernels, someone will think through how to be consistent in bindings between them. This will be a stickier wicket. Living in emacs org-mode now with poor consistency in this regard is a bit of a pain.
(mostly lurking, but thanks for vscode-R)
@maxheld83 Thank you for the suggestion! I'm inclined to agree with @bersbersbers and @malcook that these shouldn't be defaults. A setting to enable RStudio-like keymaps (disabled by default) is an option although someone would need to volunteer to implement it.
We have a keybindings page in the Wiki: https://github.com/Ikuyadeu/vscode-R/wiki/Keyboard-shortcuts We could add the suggested keybindings to an RStudio-like keymaps section there? Then users who want them can do a quick copy-paste into their keybindings.json
.
We could add the suggested keybindings to an RStudio-like keymaps section there? Then users who want them can do a quick copy-paste into their
keybindings.json
.
You could also add a default-false setting such as config.latex-workshop.bind.altKeymap.enabled
in LaTeX Workshop and scope two sets of key bindings to that. That's how they implement it:
https://github.com/James-Yu/LaTeX-Workshop/blob/f6016f6dd15992894935545e25ef1a6a2b6ef411/package.json#L481-L577
I think this is a great idea in general, and it would allow maintaining one (default) set of key bindings with maximum compatibility to VS Code, and another for RStudio users that can be enabled using a single setting.
The flymaps extension provides a keymap for Alt+- and Ctrl+Shift+M, a good start I think. Continuing the keymap development there would allow this extension to be installed and perhaps configured separately.
Doing this via the flymaps extension sounds fine, and adding a setting to switch on RStudio-like keymaps sounds fine too. I'll mark this as help wanted - volunteers welcome.
Describe the solution you'd like
I'd love it if there was a way to quickly get the key bindings that I (and I suspect many others) have muscle-memoried from RStudio.
Caveats:
devtools::load_all()
orR CMD check
and not the general-purpose IDE/Editor bindings (i.e. CTRL+1 for "move to source editor". VSCode is a different beast and has a completely different design, so it doesn't make sense for it to behave like RStudio all around. As a heuristic, only those keybindings should be enabled which only make sense inside R projects. If there's already a native, cross-language VSCode shortcut, that should take precedence."when": "editorLangId == r || editorLangId == rmd && editorTextFocus"
.Here's what I have so far (using tasks as per #59):