Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easily comment (C++) code in vim

Tags:

c++

vim

I have looked at the following question:

How to comment out a block of Python code in Vim

But that does not seem to work for me. How do I comment code easily without resorting to plugins/scripts?

like image 465
Samaursa Avatar asked Mar 25 '11 20:03

Samaursa


1 Answers

You can add this to your .vimrc file

map <C-c> :s/^/\/\//<Enter>

Then when you need to comment a section just select all lines (Shift-V + movement) and then press CtrlC.

To un-comment you can define in a similar way

map <C-u> :s/^\/\///<Enter>

that removes a // at begin of line from the selected range when pressing CtrlU.

like image 85
6502 Avatar answered Oct 20 '22 04:10

6502