How to comment/uncomment code in Spacemacs

Add a layer

Learn how to add a layer. Add evil-commentary as a layer:

shows evil-commentary as line in config file

Open a code file

I chose a JavaScript file:

shows a JavaScript file with some code in it

Comment a single line

Put your cursor on a line, and press g c c:

shows a commented out line in Spacemacs

You can use the same shortcut to uncomment the line.

Comment using Vim motions

You can type g c followed by a Vim motion to comment sections of code.

For example, we can comment out three lines with g c 3 j:

shows 3 lines commented out

Comment a visual mode selection

You can use v to enter visual mode and select text (hjkl):

shows some lines selected in a Vim visual mode

Then press g c to toggle comments:

shows 4 lines commented out

Documentation

See the documentation for more shortcuts.

Next: How to setup AG (Silver Searcher) to find text in files in Spacemacs on Windows

Comments

Leave a comment

What color are brown eyes? (spam prevention)
Submit
Code under MIT License unless otherwise indicated.
© 2020, Downranked, LLC.