- gcc comments out a line (takes a count)
- gc comments out the target of a motion, e.g. gcap to comment out a paragraph (normal state) and gc to comment out the selection (visual state).
This package is a port of the vim-commentary plugin for Vim. I wrote this because I really admire the work of tpope, its author, and wanted to have something really simple (less than 100 lines) like vim-commentary.
evil-commentary is considered feature complete as of
though additional integrations may be added in the future.
The easiest way to install
evil-commentary is to use
obtain it from Melpa:
M-x package-install RET evil-commentary RET
You can now try it with:
evil-commentary permanently, add
Alternatively, you can manually clone evil-commentary
load-path using something like this:
(add-to-list 'load-path "/path/to/evil-commentary") (require 'evil-commentary) (evil-commentary-mode)
Here is an overview of the provided commands and their default key bindings:
Comment and uncomment
The default key bindings use gc
evil-commentary operator command.
That means it can be used with all available motions and counts,
just like other operator commands, such as
gcc comments out a line,
and 3gcc comments out three lines.
Try gcap to comment out a paragraph
or to uncomment a paragraph that is already commented out.
evil-commentary can also be used in the
ex command line,
which is usually brought up by pressing
:. As an example,
toggles comments on all lines that contain the string "TODO".
The default bindings also bind super+/
evil-commentary-line, which comments out a single line,
since that is the de facto standard shortcut in many text editors.
It also works in
(Keep in mind that
evil is still required.)
Copy and comment
When editing code,
it is common to try different variations of a piece of code,
or to run a program with different settings.
This is where
evil-commentary-yank-line) can be very helpful.
This command does the same as
but also copies the original (uncommented) code
so that it can be easily pasted and modified afterwards.
By default, this functionality is bound to gy.
As an example, gyyp comments out a line of code (gyy)
and puts the original line of code after the current one (p).
evil-commentary uses the
It is possible to specify a different comment function by adding it
evil-commentary-comment-function-for-mode-alist, which is an
alist that maps a major mode (a symbol) to a comment function
(also a symbol).
A comment function must accept
end (both buffer positions)
as its required parameters. You can use the source code for the bundled
integrations as an example.
You can bind
other keys than the defaults. For example:
(define-key evil-motion-state-map "," nil) (evil-define-key 'normal evil-commentary-mode-map ",c" 'evil-commentary) (define-key evil-commentary-mode-map (kbd "M-;") 'evil-commentary-line)
If you think that ,cc is more convenient,
have a look at evil-space to keep