Visual Studio's automatic formatting keeps the code you write, as well as code you paste into the editor, formatted as set by your preferences. Alternately, right-click the selection and select Execute in Interactive.
You can also select code and press Ctrl+ Enter to apply that entire selection. With Ctrl+ Enter, then, you can effectively step through your code from the editor. Pressing Ctrl+ Enter in the R editor sends the current line of code to the interactive window, then places the cursor on the next line. Many developers like to write some code in the editor and then send that code to the interactive window for immediate testing (also known as a Read-Evaluate-Print-Loop or REPL). Peek Definition, invoked from the right-click menu or Alt+ F12, inserts a read-only, scrollable region containing the source code of the function below the function call: The cursor is conveniently positioned at the start of the function definition. This command opens a new editor window containing the source code for the function. Just right-click the function of interest and select Go To Definition, or place the cursor in the function and press F12. Go To Definition quickly jumps to a function definition or pops up an inline mini-editor to read the source code of a library function. These features keep you in the flow of your work rather than having to manually search your code. Code navigationĬode navigation gives you quick access to the source code of your R program and its libraries. You can again change this behavior as described on Options, Text Editor, Tabs. The small +/- controls to the left of the code lets you then expand and collapse regions:īy default, Visual Studio inserts spaces when you press the Tab key. To create a region of your own, surround the desired code with comments that end with. Visual Studio creates various regions for you automatically, as for multi-line statements, unless the Advanced > Outlining > Code outlining option is set to Off. To change this behavior, see editor options for the Tabs group.Ĭollapsible code regions let you temporarily hide part of code in the editor. RTVS remembers the indentation your set for parameters and automatically applies that indentation for subsequent lines: When typing calls to functions that have many parameters, often you want to line up the parameters to make the code easier to read.
It also does automatic formatting such as completion of braces and parenthesis: Edit and organize codeĪs you type code, RTVS provides auto-completion as described on the IntelliSense page. To change this behavior, see the Advanced > Syntax check setting under editor options. Visual Studio also underlines syntax errors in the editor: To customize fonts and certain highlight colors, select the Tools > Options command, navigate to Environment > Fonts and Colors, then change settings for R-related items in the Display items box: In addition to coloring different parts of your code, such as strings, comments, and keywords, RTVS also highlights and enables links in comments: In addition to the features in this article, also see IntelliSense, linting, code snippets, and R Markdown.
(For example, if you prefer VIM key bindings, you can install the free VsVim extension from the Visual Studio Marketplace.) R Tools for Visual Studio (RTVS) tailors the Visual Studio editing experience specifically for R while retaining all the features and the ability to use extensions.
Applies to: Visual Studio Visual Studio for Mac