I thought it would be handy to create a mapping that would turn the current line or visually selected line into a comment banner.
Something like this:
This is the description of the usage of the class
would become, after pressing a shortcut:
/*----------------------------------------------------*/
/* This is the description of the usage of the class  */
/*----------------------------------------------------*/
                To comment out a single line in Vim, enter Visual Mode by pressing Ctrl + V . Next, navigate to the line you wish to comment out and press the C key. Depending on your Vim configuration, this should comment out the selected line. That's all there is to it – easy, isn't it?
Hit Ctrl + q in GVIM or Ctrl + v in VIM, then go down to select first character on the lines to comment out. Then press c , and add the comment character.
To comment out multiple code lines right-click and select Source > Add Block Comment. ( CTRL+SHIFT+/ ) To uncomment multiple code lines right-click and select Source > Remove Block Comment. ( CTRL+SHIFT+\ )
I have this line in my ~/.vimrc that does exactly what you want:
nnoremap <leader>g I/* <Esc>A */<Esc>yyp0llv$r-$hc$*/<Esc>yykPjj
Place your cursor on a line, press <leader>g, done.
The default <leader> is \, so that would be \g.
You can, obviously, use any shortcut you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With