Skip to content

Add auto-lists #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Add auto-lists #53

wants to merge 4 commits into from

Conversation

RobertAudi
Copy link

This feature lets Vim automatically add a new list item on (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.

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.
@RobertAudi
Copy link
Author

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
Copy link
Author

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.)

…details.

Bug:
----
When the caret is on a list item, somewhere in the middle of the line,
and the user presses `<CR>`, then a new list item is added on a new line
instead of splitting the current line. This commit partly fixes that
bug.

Caveat:
-------
When the caret is on a list item, at the character previous to the last
one (`col('$') - 1`), and the user presses `<CR>`, then a new list item
will be added on a new line instead of splitting the current line.
@tpope
Copy link
Owner

tpope commented Oct 24, 2013

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

endf

" Remap <CR> for all .md files
au BufEnter *.md inoremap <buffer> <CR> <C-o>:call AutoMDList()<CR>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should probably be a FileType autocommand instead, and match markdown.
It is rather tricky to setup the CR mapping, because existing maps should get handled / forwarded.
Take a look at how endwise handles it. I have just submitted a PR to improve upon it: https://github.com/tpope/vim-endwise/pull/50/files

@blueyed
Copy link

blueyed commented Feb 4, 2014

@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.

@thejspr
Copy link

thejspr commented Sep 20, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants