Moving to matching braces in RStudio - r

I have several R functions which I am scripting in RStudio. These functions are quite long. Is there a keyboard shortcut to skip from an opening brace to a closing brace in RStudio so I can more efficiently run these functions without having to scroll the script file?

One can use Ctrl+p to navigate to the closing brace/parenthesis.
You can also check the keyboard shortcuts in the Menu bar -> Tools -> Modify Keyboard Shortcuts.
Or from https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts
Jump to Matching Brace/Paren Ctrl+P

In the RStudio v1.4 preview there is matching parentheses, braces, and brackets in a series of colors. This is customizable in the theme CSS. It can also be turned on/off dynamically per document through the Code -> Rainbow parentheses option. See here.

Related

Is there a way to preserve the highlight when wrapping a selection with quotes/brackets in RStudio?

In many IDEs, there's a feature where you can highlight a section of code and then press a key like ", ', (, or [ (to name a few) to surround the highlighted section with the corresponding open/close characters of the given key. In Jupyter Notebooks, the highlighted portion stays highlighted after surrounding the code with the desired characters. However, in RStudio the text cursor falls to the end of the highlighted section after pressing the key to surround the code with.
I find the behavior of this feature in Jupyter much more desirable since I can press either the left or right arrow keys to immediately place the text cursor on either side of the selected code (without touching the mouse no less). But in RStudio I find myself constantly surrounding code in parentheses or quotes then spamming the left arrow key to get the text cursor to the beginning of the code I just highlighted.
Is there a way to change this setting in RStudio to match the behavior in Jupyter Notebooks? This is the only other question I've found relating to this behavior in RStudio, but unlike OP I want to alter the behavior of this setting, not turn it off completely.
I have looked in Tools > Global Options... under the Code tab (per the link above), but don't see any obvious solution there.
EDIT: I found from this question that I can use Option+J and Option+L (Mac) or Alt+J and Alt+L (Windows) to navigate the cursor to the other end of a word quickly, but I'm still curious if anyone knows of a way to match the settings in RStudio with the behavior of Jupyter Notebooks.

R Studio Server shortcut for closing current tab

I am searching for the shortcut to just close the current tab in the server version of R Studio.
Ctrl+W is occupied by the browser. Ctrl+Shft+W closes all browser tabs. Cltr+Alt+W does nothing and Ctrl+Shft+Alt+W closes all R tabs without the current one.
Is there btw a shortcut to undo the last combination?
A suitable workaround was to just change the shortcut. R Studio allows to set own shortcuts and modify existing ones in the menu. Just go to the toolbar and on "Tools\Modify Keyboard Shortcuts...". I simply set it to Ctrl+Alt+W, because that's unused and somewhat consistent to the fact, that Ctrl+Alt+Shft+W closes all documents that are opened in R Studio, by default.

How to quickly view a function's documentation when using jupyter-notebook

It seems that using '?' command is the only way.But this is too much trouble, need to run the function? in another cell.
I've tried shift+tab, but it does not work for me.
Shift + TAB displays popup with signature, docstring and type.
One can also keep open Inspector where documentation will be displayed while typing.

Ctrl+P and Ctrl+N for navigation in jupyter notebooks

I'm used to Emacs navigation, in particular Ctrl+P, N, F, and B, but I'm also used to Jupyter notebooks by now. The general question is: how to enable those shortcuts in a notebook?
What tickles me is the fact that on Mac those keybindings are already in place in a standard Anaconda IPython. But it's perfectly understandable since most system and browser shortcuts are bound to Cmd instead of Ctrl.
Since I spend a lot of time in Ubuntu, I wanted to reproduce the same behaviour here. It soon became apparent that most browsers hold some of the keybindings very dearly, such as Ctrl+P for print or Ctrl+N for New window. Turning these off is a huge matter in itself, so I decided to use another browser solely for the Jupyter Notebook, and Vivaldi seems like a nice choice since all shortcuts are easily customizable there.
I believed that with browser shortcuts being turned off, the IPython syntax would kick in, but none such thing has happened. Next I tried one of many manuals on the Jupyter notebook shortcuts customization (such as this one http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Custom%20Keyboard%20Shortcuts.html) to bind the 4 shortcuts I need. It works only up to some extent and only in the Jupyter inline magic:
%%javascript
Jupyter.keyboard_manager.command_shortcuts.add_shortcut('ctrl-p', 'jupyter-notebook:move-cursor-up')
What it does is that occasionally now the cursor in command mode does indeed move up when I press ctrl-p, but this behaviour is unstable. Moreover, after it moves, it immediately enters the edit mode in the cell above, which isn't happening if I simply press 'Up' arrow. As for the same trick for the edit mode:
%%javascript
Jupyter.keyboard_manager.edit_shortcuts.add_shortcut('ctrl-p', 'jupyter-notebook:move-cursor-up')
alas, it doesn't work at all.
Forgive me for the prolonged intro. The questions I have now are:
What is wrong with the key bindings I use in inline mode? Is it a silly mistake I made or a Jupyter glitch?
When I try to use these byndings through my custom.js file, they do not work. However, the file itself is recognized, e.g. the alert() commands work perfectly fine.
I've stumbled a few times on a emacs-bindings for the CodeMirror, however, as far as I understood, they are mostly used for copy-paste related matters rather than navigation, is it true? Would it help to use this set of bindings instead of pursuing the path with custom.js?
Thank you.
UPD
Installing emacs.js from CodeMirror and adding this code actually solved my problem. Just had to make sure that all conflicting browser keybindings were turned off.
require(["codemirror/keymap/emacs", "notebook/js/cell", "base/js/namespace"],
function(emacs_keymap, cell, IPython) {
cell.Cell.options_default.cm_config.keyMap = 'emacs';
var cells = IPython.notebook.get_cells();
for(var c=0; c< cells.length ; c++){
cells[c].code_mirror.setOption('keyMap', 'emacs');
}
}
);

How to turn off syntax highlighting in R-studio

I am very new to R-Studio. I was used to RGui, where there was no syntax highlight and the letters were very contrasty:
In R-Studio, the letters seem to be very dim, even the "black ones" doesn't seem as black as in RGui:
I don't have a clue how to change the colors (do you?) so I decided to turn off the syntax highlight completely. But I haven't found any way to do it. I tried Tools / Global Options, Appearance and Code Editing, but haven't found anything to change colors or turn off syntax highlighting.
I don't know of a way to turn off syntax highlighting completely. But it is possible to choose a different theme. Go to Tools - Global Options - Appearance and try the various settings for Editor theme. Maybe changing the font or font size could also improve readability.
Another option is to turn off syntax highlighting in a open file. In the lower right corner of the editor window, you should see R Script (or something else, if you are not currently editing an R Script) with two little arrows next to it:
When you click it, you can choose the language to use for syntax highlighting. If you pick Text File, there should be no highlighting at all. But you will have to redo this step whenever you load a file. At least, when you keep a file open in the editor and close RStudio, the setting will be kept when you start RStudio the next time.
I'm afraid you can't turn off syntax highlighting. There is only option to show syntax highlighting in console input. But you can still change the colors :)
Tools -> Global Options -> Appearance -> Editor Theme

Resources