Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Does vscode-R have some functionality that enables autoformatting of code with a shortcut?

I'm imagining something similar to what was described in this post:
https://stackoverflow.com/a/34856235/15481857

You must be logged in to vote

Replies: 2 comments · 4 replies

Comment options

You could bind shortcut keys to the following in "Keyboard shortcuts":

{
  "key": "shift+alt+f",
  "command": "editor.action.formatDocument",
  "when": "editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly && !inCompositeEditor"
},
{
  "key": "cmd+k cmd+f",
  "command": "editor.action.formatSelection",
  "when": "editorHasDocumentSelectionFormattingProvider && editorTextFocus && !editorReadonly"
}
You must be logged in to vote
4 replies
@werkstattcodes
Comment options

Apologies for intruding your conversation - I was also looking for a formatting shortcut and inserted the code above. As a response I get that no formatter is installed; when trying to install a formatter, the reply is that there is no formatter for quarto (which I am using with R). Is there something I can do about it? Would imagine many VS Code & R Users will also use quarto. Many thanks.

@renkun-ken
Comment options

Maybe https://github.com/quarto-dev/quarto-vscode/issues is a better place to ask? Not sure if how formatters come into play in a document with embedded languages provided by external language servers.

@JacobBumgarner
Comment options

Thanks for this, @renkun-ken.

I wonder if this could be highlighted in the wiki?

@JacobBumgarner
Comment options

And FYI for future mac users:

"option + shift + F" is already bound to "Format document" by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
💡
Ideas
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.