When I write //
comments in Java, and press Enter, vim helpfully adds a //
to the beginning of the next line.
// This is the first line of my comment <CR>
// <-- these were added automatically by auto-comment.
As I say, this is helpful behaviour (I use //
for multi-line comments to make it easy to comment out large blocks of code with /*...*/
, and use /**...*/
only for Javadoc comments). But when I've reached the end of a comment, I have to press the backspace key three times to get rid of the //
at the beginning of the line that I now no longer want.
Is there a keyboard shortcut from Insert mode that can tell Vim that I'm no longer writing a comment? Or do I have to write my own?
Since Vim cannot guess your thoughts (yet), you have to tell it explicitly when a new line does not continue a multi-line comment.
A straightforward solution is to simply delete the autoinserted comment leader with CtrlU in insert mode. See :h i_CTRL-U
.
This key combo also works in most terminals, by the way.
In case you don't like autoinserted comment leaders at all, you can disable them with the command :set fo-=ro
. See :h 'formatoptions'
.
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