Comment lines in Vim
Often I have to comment out a line of code. The following 2 maps helped me with speeding up my workflow. cl
to comment a line and ucl
to uncomment a line
:map cl 0i//<Esc>
:map ucl 02x
Explanation
-
0
jumps to the first first character (including whitespaces) of the current line. -
i
changes to the insert mode -
//
will insert 2 slashes. For other programming languages where you something else for commenting out a line, you need to replace this. As an example I would replace the//
with--
for Eiffel. -
<Esc>
switches back to normal mode.
The ucl
command is even easier.
-
0
jumps to the first character (including whitespaces) of the current line. -
2x
delets 2 characters starting at the cursor position.
Written by Sandro Meier
Related protips
2 Responses
Or try NERD Commenter (http://www.vim.org/scripts/script.php?script_id=1218)
over 1 year ago
·
That script is awesome. I didn't know about that one.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vim
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#