How to comment a description line using vim?

I thought it would be convenient to create a mapping that would turn the current line or visually selected line into a comment banner.

Something like that:

This is the description of the usage of the class

would become after clicking the shortcut:

/*----------------------------------------------------*/
/* This is the description of the usage of the class  */
/*----------------------------------------------------*/
+5
source share
1 answer

I have this line in mine ~/.vimrc, which does exactly what you want:

nnoremap <leader>g I/* <Esc>A */<Esc>yyp0llv$r-$hc$*/<Esc>yykPjj

Place the cursor on the line, click <leader>gdone.

The default <leader>value is equal \, therefore it will be \g.

You can obviously use any shortcut you need.

+9
source

All Articles