In Vim, I like the feature that allows you to auto insert comments after you have started a comment block. How would you make it so that you get a comment character(s) after a newline, but upon getting a second newline that comment is removed and you start a newline without a comment character. This would be helpful if you are working on a comment block and don't want to make anymore comments after that (in my case I also want to apply the same thing to markdown lists, treating */- as comment characters).
For example
// typing a comment
// (cursor here after hitting enter once)
And
// typing a comment
(cursor here after hitting enter twice)
This mapping checks if the current line contains only comment leaders before deciding if it does <C-u>
or <CR>
:
inoremap <expr> <CR> getline(".") =~ '^\s*\(\*\|//\|#\|"\)\s*$' ? "\<C-u>" : "\<CR>"
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