Reputation: 45642
In Vim, I can type a line like this:
- When in the Course of human events it becomes necessary for one people
to dissolve the political bands which have connected them with another
...
and Vim will wrap the text so that it aligns to the right of the dash. But if I try this with an asterisk, this is what happens:
* When in the Course of human events it becomes necessary for one people
to dissolve the political bands which have connected them with another
...
Is there a way to make the autoindent work with the leading asterisk in the same way it does for the leading dash?
Upvotes: 11
Views: 2016
Reputation: 72696
This is done using the comments
setting (see :help 'comments'
and :help format-comments
).
The setting you need to add is fb:*
, which says that there is a comment type that starts with *
and the *
must be followed by a blank and is only on the first line of the comment. Vim handles the rest. However, note that default settings include *
as the middle of a multi-line C comment, so you'll need to disable this.
If the hyphen-prefixed and asterisk-prefixed lines are the only ones you want to work like this, do this:
set comments=fb:-,fb:*
Alternatively, tweak the default comments setting as you like: :set comments?
shows the current setting and :help format-comments
explains what it all means.
If you want this to be specific to a file type, create a file in ~/.vim/ftplugin
(or vimfiles
on Windows) with a filename as extension.vim
(e.g. txt.vim
for .txt
files). In this file put:
setlocal comments=fb:-,fb:*
This will configure the comments
setting for the relevant file type without affecting other files.
Upvotes: 16