Visual Studio Code (VS Code)
1 Tips and Tricks
- You can view the source code side-by-side with the Preview (after selecting the code type in the bottom right):

- To create personalized CSS commands in VS Code, see here.
- To wrap code around the selected text (https://stackoverflow.com/a/73344832/2029527; archived at https://perma.cc/P5JA-7DBC):
- Press
Ctrl+Shift+p - Type and select “Open Keyboard Shortcuts (JSON)”
- Add the following item:
[ { "key": "alt+shift+e", "command": "editor.action.insertSnippet", "when": "editorTextFocus", "args": { "snippet": "<TEXT-BEFORE>$TM_SELECTED_TEXT</TEXT-AFTER>" } } ]- Save the
keybindings.jsonfile. - Select the text you want to wrap, and press
Alt+Shift+e
- Press
2 Example Code Snippets
2.1 Template
[
{
"key": "alt+shift+e",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "<TEXT-BEFORE>$TM_SELECTED_TEXT</TEXT-AFTER>"
}
}
]
2.2 \begin{equation}...\end{equation}
[
{
"key": "alt+shift+e",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "\\begin{equation}\n$TM_SELECTED_TEXT\n\\end{equation}"
}
}
]
3 Connect to R
- Install
Rusing the initial setup instructions described here: https://devpsylab.github.io/DataAnalysis/R.html#sec-setup - Install the
Rextension forVSCode - Go into the
Rextension settings - Set the
rpathvariables (e.g.,r.rpath.windows) to be blank - Set the
rtermvariables (e.g.,r.rterm.windows) to be blank - Close VS Code
- Set VS Code to Run as Administrator by default
- Open VS Code as Administrator
- Launch the R terminal (Ctrl+Shift+P → “R: Create R terminal”).
VS Code extensions to install: - Quarto
R packages to install: - install.packages(c("languageserver","httpgd")) - languageserver is used for syntax highlighting and code completion - httpgd is used for plotting in VS Code
3.1 Old Instructions
Follow the instructions here to connect VSCode to R: https://stackoverflow.com/a/66069540/2029527 (archived at https://perma.cc/FCF5-26BT)
- Install
Rusing the initial setup instructions described here: https://devpsylab.github.io/DataAnalysis/R.html#sec-setup - Install the
Rextension forVSCode - Go into the
Rextension settings - Set the
Rpath to the path of yourRinstallation:- e.g.,
C:\\R\\R-4.3.1\\bin\\x64\\R.exe
- e.g.,
- Set the
Rtermpath to the path of yourRinstallation- e.g.,
C:\\R\\R-4.3.1\\bin\\x64\\Rterm.exe
- e.g.,