Open MayMAAhmed opened 8 years ago
Not trivial! Important.
I use Code > Reflow comment a lot to have RStudio insert line breaks in comments. Because I do it so often I assigned it a keyboard shortcut, which you can set up via Tools > Global Options > Code > Modify keyboard shortcuts.
How do we use this? Do we have to insert this for each comment (before the #?)? Or do we put it at the start of the file?
Every line that is a comment (as opposed to code) must have #
at the start.
Some languages have a concept of multi-line comments, where you signal comment start ... then eventually indicate comment end. R is not one of them.
Therefore, when you're writing a long comment, it's nice to have help breaking it into lines. Each of which must begin with at least one #
.
Code > Reflow will help with this, when cursor is inside a really long comment. And when you grow weary of using a menu, you can set up a keyboard shortcut for it.
Thanks. I understand how to make text into a comment (put #
in front of each line), but how do I use Code > Reflow
? Do I put it after the # at the start of each longer-than-one-line comment? Probably not, since then it would be treated as part of the comment. Do I put it before the #
? Or do I only need to use it once, putting it somewhere at the start of the file?
I tried using the code-> reflow comment, but wasn't sure how to use it I guess, so I tried this: Tools>Global options>code>soft wrap R source and it seemed to work. @jennybc what do you think?
@RosieRedfield Code > Reflow is an action, like "Save", not a thing like #
. So if your cursor is in a comment that's running past the end of line, executing Code > Reflow will cause line breaks to go in. It's not something you can insert in a comment to get that behaviour automatically. The need to re-execute Code > Reflow a lot is why I gave it a keyboard shortcut.
@MayMAAhmed No I don't think soft-wrapping of code is a good idea. I think you should have hard line breaks in code and explicitly break things into lines in a principled way.
Ah, I see. Reflow Comment is an RStudio command under the Code menu. It inserts appropriate line breaks and #s into a comment you've already typed. If you keep adding to the comment you'll need to do Reflow Comment again.
And there's an existing keyboard shortcut: Command/Shift// (hold down Command and Shift, and type a slash).
Also: do not use Code > Reflow when your cursor is not inside a comment! It messed up the indentation of my entire Rmd file.
@RosieRedfield I migrated to RStudio after 15+ years of Emacs + ESS and I think I changed the keyboard shortcut to match the one burned into my brain. But if you don't have this, just use the build-in shortcut!
@ksedivyhaley YES. I too ave suffered from this to a certain extent. It only happens in Rmd, not R. It's one reason I save a lot (fairly easy to revert to saved) and commit a lot (definitely easy to go back to last committed version).
Might seem like a trivial and random question, but I was wondering if there is a way that when I write comments for myself they automatically go to a next line without wandering off to extra long line.