vim-markdown
vim-markdown copied to clipboard
Add auto-lists
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.
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.
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.)
This is pretty cool. Since it ships with Vim by default, it needs to be absolutely 100% robust before making it in.
@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.
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