Skip to content

Instantly share code, notes, and snippets.

@Zequez
Last active February 26, 2023 15:19
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Zequez/48804fff798e4c98f288 to your computer and use it in GitHub Desktop.
Save Zequez/48804fff798e4c98f288 to your computer and use it in GitHub Desktop.
Comment out JSX code on Atom
# If you worked with React and JSX you probably noticed that you can't use JS comments when inside JSX sections
# Add this to your Atom init script
# Then add 'ctrl-cmd-/': 'comment-jsx' to your keymap.cson
# Then when you are on a JS/JSX file, just press cmd+ctrl+/ to use JSX-style comments that work with JSX elements
# Is not the most efficient way, but it's the cleanest and reliable one
atom.commands.add 'atom-workspace', 'comment-jsx', ->
atom.config.set('editor.commentStart', '{/*', {scopeSelector: '.source.js.jsx'})
atom.config.set('editor.commentEnd', '*/}', {scopeSelector: '.source.js.jsx'})
for selection in atom.workspace.getActiveTextEditor().selections
selection.toggleLineComments()
atom.config.unset('editor.commentStart', {scopeSelector: '.source.js.jsx'})
atom.config.unset('editor.commentEnd', {scopeSelector: '.source.js.jsx'})
@derekclair
Copy link

Thank you! Just to clarify, your keymap.cson should look like:

'atom-workspace':
  'ctrl-cmd-/': 'comment-jsx'

@morenoh149
Copy link

Your init.coffee and keymap.cson typically reside in ~/.atom/.
If you have jsx in your .js files you can simply change all the extensions to .js, e.g., scopeSelector: '.source.js'.

@mqklin
Copy link

mqklin commented Oct 7, 2016

You better use https://atom.io/packages/language-babel, it supports this by default

@Faraday0071
Copy link

Faraday0071 commented May 5, 2017

It don't work.
Probably i am doing somethink wrong. With what do you open csno files?

@damianobarbati
Copy link

Not working, it comments with // as the built-in comment.

@arnovanoordt
Copy link

I know Atom has been sunset by now but if someone is still looking for a package that can handle jsx commenting you can find it here: https://github.com/tom-mckinney/jsx-comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment