-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
base: master
Are you sure you want to change the base?
Add auto-lists #53
Conversation
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.
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. |
…lists and replace useless `if` statements by a single line
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 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 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.
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> |
There was a problem hiding this comment.
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
@azizLIGHT Couldn't this be made a separate plugin? |
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 |
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.