vim-markdown icon indicating copy to clipboard operation
vim-markdown copied to clipboard

Add auto-lists

Open RobertAudi opened this issue 12 years ago • 5 comments

This feature lets Vim automatically add a new list item on <CR> (or end a list if the list item is blank). In the case of ordered lists, the list item number is incremented.

This is a prototype, an idea. It seems to work normally, but one feature is missing, because I don't know how to program an efficient implementation:

If a list item spans over multiple lines, a list item won't be added.

RobertAudi avatar Oct 19 '13 15:10 RobertAudi

NOTE: I could have implemented this feature by adding two "comment types", but the ordered list item numbers would not be able to auto-increment. I am aware that as far as the parser is concerned, it doesn't matter as long as there is a number, but I find it a lot more readable to have incrementing numbers.

RobertAudi avatar Oct 19 '13 15:10 RobertAudi

I just realized there is a small bug in this pull request:

If the user is in the middle of a list item line, and presses <CR>, a new list item will be added on the next line instead of splitting the line.

I am working on a fix, but believe it or not, it's not that easy. Basically, I need to detect if the caret is at the end of the line in insert mode. But using col('$'), I get the column number of the previous character to the last one...

If you have any suggestions, please don't hesitate.

(I'm on my phone right now — Thank you iOctocat — and on the train, so I have no internet connection. I'll add some details about the bug and my problems solving it when I arrive home.)

RobertAudi avatar Oct 20 '13 15:10 RobertAudi

This is pretty cool. Since it ships with Vim by default, it needs to be absolutely 100% robust before making it in.

tpope avatar Oct 24 '13 04:10 tpope

@AzizLight Nice. I am just looking around for something like this.

Couldn't this be made a separate plugin? Lists in texts are not specific to markdown, and it would be useful if it was not bound to markdown files only.

blueyed avatar Feb 04 '14 03:02 blueyed

I found vim can do the heavy lifting on this:

autocmd bufreadpre *.md setlocal com=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,b:- formatoptions=tcroqln

source: http://stackoverflow.com/questions/9065967/markdown-lists-in-vim-automatically-new-bullet-on-cr

thejspr avatar Sep 20 '14 08:09 thejspr