Oscar Godson
Oscar Godson

Reputation: 32726

Add asterisks in block comments with vim

How would I implement something where when I type

/**<Return>

It'll create

/**
 * |

Where the pipe == the cursor and as long as I keep making new lines of text and pressing enter it'll keep adding *<Space>s in.

And if I leave an empty line like:

/**
 * Foo bar baz...
 * <Return>

It'll close it like

/**
 * Foo bar baz...
 */
|

Upvotes: 2

Views: 2055

Answers (1)

romainl
romainl

Reputation: 196546

This behavior is dictated by set formatoptions, see :help fo-table for all the possible values for this option.

Verify your current setting with :set fo?. You want the letter r to be present. If it's not, execute :set fo+=r to add it.

Add set formatoptions+=r to your ~/.vimrc to make the change stick between sessions.

Upvotes: 9

Related Questions