Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to indent multiple lines of code in Rstudio?

Tags:

r

rstudio

I have tried using "reindent lines" after highlighting the lines but that doesn't work (in fact it removes indentation). For example I want a quick way to

take a script like this

#parameters
b=2
c=1
d=4
q=3

and turn it into this

#parameters
    b=2
    c=1
    d=4
    q=3

in Rstudio

like image 508
WetlabStudent Avatar asked Jun 12 '13 03:06

WetlabStudent


People also ask

How do you indent multiple lines of code?

Select the lines you want to indent, and. use Ctrl + ] to indent them.

How do I indent R script?

Magic shortcut: Command+I ( Ctrl+I for Windows/Linux) will indent a selected chunk of code.

How do you indent a set of lines?

To indent the first line of a paragraph, put your cursor at the beginning of the paragraph and press the tab key. When you press Enter to start the next paragraph, its first line will be indented.


2 Answers

Highlighting the code of interest and hitting tab should add another level of indentation. Shift-tab will remove a level of indentation.

like image 181
Dason Avatar answered Sep 20 '22 16:09

Dason


You could use a shortcut. First, highlight the lines you want to indent, and then press: Ctrl + } (at least, that is the combination on my keyboard).

If you want to move in the other direction, then press: Ctrl + {.

like image 42
Sebastián Gómez Roca Avatar answered Sep 19 '22 16:09

Sebastián Gómez Roca