Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you get Vim to wrap bulleted text with indentation?

Tags:

vim

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?

like image 832
dan Avatar asked Jan 24 '11 13:01

dan


People also ask

How do you add bullet points in Vim?

Usage. In markdown or a text file start a bulleted list using - or * . Press return to go to the next line, a new list item will be created.

What is bullet indentation?

Bullet points use three important markers to determine where the bullet and the text will appear. First Line Indent - This is the distance from the left margin to the bullet and indicates if there is any indentation. All the built-in bullet formats are indented by 0.63cm.


1 Answers

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.

like image 144
DrAl Avatar answered Sep 28 '22 19:09

DrAl