evil-nerd-commenter (current version 0.0.2)
As a developer, I often need comment/uncomment lines for debugging or adding some short comment in the code block.
As I know, the Nerd Commenter for Vim is the most efficient way to doing this thing. Unfortunately, there is no similar plugin in Emacs.
That’s why I develop this Nerd Commenter simulator for Emacs people.
Why evil-nerd-commenter is better? Show me a simple use case!
Say you want to comment out nine lines. Instead pressing “C-space M-9 C-n M-;”, now you can press “M-9 M-;” or “,9ci”.
Install
evil-nerd-commenter is already uploaded to http://marmalade-repo.org/. So the best way to install it is using Emacs’ package manager.
Set up
Nothing to set up.
You may add below line into ~/.emacs which use hotkey “M-;” to toggle comment:
(evilnc-default-hotkeys)
The advantage of use “M-;” is you can set mark on the first line and scroll serveral pages down and comment all the lines in that region by “M-;”.
I prefer vi key binds. So I also use evil-mode and evil-leader.
Here is my configuration for evil-mode:
(require 'evil)
(require 'evil-leader)
(setq evil-leader/leader "," evil-leader/in-all-states t)
(evil-leader/set-key
"ci" 'evilnc-comment-or-uncomment-lines
"cc" 'evilnc-comment-or-uncomment-to-the-line
)
Usage
These are available commands:
- evilnc-comment-or-uncomment-lines
- comment/uncomment lines.
- evilnc-comment-or-uncomment-to-the-line
- comment/uncomment from current line to the specified line.
Example 1: “C-u NUM M-x evilnc-comment-or-uncomment-lines”, comment/uncomment next NUM lines.
Example 2: Select a region and “M-x evilnc-comment-or-uncomment-lines”. The region will automatically expand to contain whole lines. Then comment/uncomment the region.
Example 3: If you use evil-mode and get the package evil-leader installed. Comment 9 lines could be as easily as type “9<Leader>ci” (only four keys).
Example 4: “C-u 56 M-x evilnc-comment-or-uncomment-to-the-line”, comment/uncomment from current line to line 56.
Contact me
You can report bugs at https://github.com/redguardtoo/evil-nerd-commenter. My email is <chenbin DOT sh AT gmail>.
License
Copyright (C) 2012 Chen Bin
Author: Chen Bin <chenbin DOT sh AT gmail DOT com
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.