In Sublime Text 3, how can I change the comment character?
Asked Answered
O

1

8

I like the auto-comment feature Ctrl + /, but I'd like to be able the change the character it uses arbitrarily. I have read many similar questions like this one, but it's not exactly a generic solution.

How can I make the comment character use something different? The specific use case is that I'm writing R code and using Roxygen2 for documentation. This uses #' as the comment character, instead of just #. So I I'd like to set sublime to use #' because as is, I can't use it for Roxygen2 comments.

Questions regarding Sublime2, like this one, refer to '.tmPreferences' files, but I have not been able to find any such files in my Sublime 3 installation. If the answer is still these files, where are they stored in Sublime 3?

Omaromara answered 14/6, 2017 at 21:43 Comment(2)
Possible duplicate of Enable automatic commenting in Sublime Text for a custom syntaxEngorge
I think that must be referring to ST2 -- do tmPreferences files exist in ST3? Where are they on a linux system?Omaromara
E
15

As mentioned in Enable automatic commenting in Sublime Text for a custom syntax, .tmPreferences files are used to specify what the comment markers are for a syntax.

To edit the comment markers for R:

  1. Install OverrideAudit
  2. Open the command palette
  3. Type OA:OR
  4. Select OverrideAudit: Open Resource
  5. Select R
  6. Select Comments.tmPreferences
  7. Edit the TM_COMMENT_START value to #' as desired
  8. Save the file
  9. Use the toggle comment functionality on an R file and see that it now uses #' instead of #
Engorge answered 16/6, 2017 at 6:55 Comment(5)
Thanks! That worked! It was impossible to find this information anywhere, I really appreciate your answer.Omaromara
Gold! ini comments using semi-colon have been bothering me for ages!Butcherbird
Thanks! I was pleasantly surprised that when you save the file it will automatically save it in your custom Packages directory (instead of overriding the build-in R package). Also, for my needs, it made more sense to add #' as an additional TM_COMMENT_START_2 rather than overriding the default. This makes roxygen blocks play nice with Wrap Plus, but I can still use either method depending on where I am at in my code.Abiotic
Life saver! Worked like a charm.Catie
WHAT A NINJA. Keith wins the internetDorotheadorothee

© 2022 - 2024 — McMap. All rights reserved.