format code feature feels cumbersome

In RStudio it is like:

  1. put your cursor anywhere in the file and press format shortcut: you will see a new line is created and selected. This almost always breaks your code.
  2. in a R file, press ctrl + A to select the whole file and press format shortcut: it is like what I expected, but a new line is added on top (why?).
  3. in a Rmd file, pressing ctrl +A won't work as the whole document is selected. I have to use expand selection (and shrink selection) multiple times to do the selection, and then press format shortcut.
    (Furthermore: if your cursor unluckily is in a "deep" position of your current code chunk, you may have to press many times of expand selection. I counted 8 times just now.)

I use PyCharm and VS Code more often. Their format code feature is like:

  1. put your cursor anywhere in the file and press format shortcut;
  2. the whole file is formatted.

If possible, I'm glad to see a code format feature whose behavior is similar to that of PyCharm and VS Code, i.e. a feature with shortcut to format the whole current file or the current code chunk where the cursor is, without doing any selection.

also, code like
a = 1 (2 spaces between = and 1. forum automatically fixes it)
won't be formatted to
a = 1 (1 space between = and 1).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.