vim-markdown
vim-markdown copied to clipboard
Auto-indentation for lists
Hi,
I believe that my problem is related to #78 and I'm pretty sure that this what I'm seeing is a deliberate choice (based on lines 41-43 of indent/mkd.vim
), but I want to make sure.
If I'm writing Markdown and I start a list-item, when I hit return, the cursor is indented one level further in than the original list-item.
Example:
Here is some text.
+ Now I start a list. Soon I will hit enter.<CR>
|<cursor is now here>
I don't understand this choice. As a user, when I'm done with the first list-item (and hit <CR>
), I expect to start typing the next list-item. So shouldn't I be at the same indentation level, rather than further in? (If I want the next list-item to start a sub-list or be code, that's a separate choice. I would then <TAB>
in further myself.)
tl;dr Is this observed indentation behavior deliberate? If so, why? Thanks.
Weird, I don't reproduce: hitting enter for me creates the new item. I'm working on adding unit tests to this lib with https://github.com/junegunn/vader.vim: when that is done we'll create tests for this and decide =)
Ah, that is interesting. It may be another plugin interaction (though I don't use many) or maybe something to do with my format-options.
On the other hand, if I remove lines 41-43 from indent/mkd.vim
, the problem goes away. So I would have sworn it was connected to vim-markdown
. Then again, there are lots of variables involved.
Can I ask you what set fo
shows for you? Thanks.
set fo
gives me tqr
.
I start with tcqn1
, but changing those options doesn't seem to matter.
I'll try with/without other plugins, but for now the only thing that works is to edit this plugin's indentation file.
I have just tried it on a minimal config with: https://github.com/cirosantilli/vundle-plugin-tester and still don't reproduce.
To try it out, clone, ./test.sh a.md
.
I'm on Vim 7.3.
I couldn't get vundle-plugin-tester
to work at all, but I've found the problem by loading only this plugin and then playing with my ~/.vimrc
. It's not a plugin interaction. Something here depends on syntax highlighting being turned on. I have syntax off
at the top of my ~/.vimrc
because I prefer no syntax highlighting.
I have this issue.
I have this issue as well
@telemachus
Make sure you have r
in formatoptions
. This is meant to start a new list entry on Enter (https://github.com/plasticboy/vim-markdown/blob/master/syntax/mkd.vim#L131-134).
Another issue here is the indentation of 4
, which is introduced in 5cd2223d4.
This gets applied when automatically wrapping on textwidth
.
TEST CASE:
-
set tw=20
- Enter:
- foo bar baz
RESULT:
- foo bar
baz
@beyondwdq (who did the commit) Was this intentional to chose 4 here? I think it's better to use the length of the found start of the list item (including any whitespace).
But for what it's worth, there are mechanisms in Vim already to get this behavior:
let &formatlistpat='^\s*\d\+\.\s\+\|^[-*+]\s\+' (from Vim's ftplugin/markdown.vim)
set formatoptions+=n
Anyone having problems with this: post the output of:
verb set flp fo ft inde comments tw
I could imagine that problems are based on using filetype mkd
by default, and Vim's default markdown handling not being applied for you then (see https://github.com/plasticboy/vim-markdown/issues/64).
I cannot see a reason for a custom indentexpr
, except if you want the odd behavior of always identing by e.g. 4
, instead of having the list aligned.
@blueyed
formatlistpat=^\s*\d\+[\]:.)}\t ]\s*
Last set from /usr/local/Cellar/vim/7.4.488/share/vim/vim74/ftplugin.vim
formatoptions=tcqn1
filetype=mkd
Last set from ~/.vim/bundle/vim-markdown/ftdetect/mkd.vim
indentexpr=GetMkdIndent()
Last set from ~/.vim/bundle/vim-markdown/indent/mkd.vim
comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
Last set from /usr/local/Cellar/vim/7.4.488/share/vim/vim74/ftplugin.vim
textwidth=79
Last set from ~/.vimrc
I suspect you're right about the filetype issue, but even if I add r
to my formatoptions manually, the problem remains. (For what it's worth, I've gone back to Tim Pope's vim-markdown, but I'm still curious about the problem.)
@telemachus Your problem is that you're missing this from the syntax file: https://github.com/plasticboy/vim-markdown/blob/master/syntax/mkd.vim#L131-L139
This does not belong into the syntax file, but should be in the filetype plugin.
For what it's worth, I've gone back to Tim Pope's vim-markdown
Makes sense, especially since it gets shipped with Vim. I'll propose a PR, trying to clean this up a bit.
I'm still interested in feedback from @beyondwdq of course.
@blueyed
Your problem is that you're missing this from the syntax file
I'm confused: I just cloned the directory today, so why would I be missing those lines?
@telemachus
You have syntax off
. You are not missing them in your checkout, but they do not get executed. See #144 - with that everybody is in your boat, but markdown
gets sourced and only the funky indenting still causes problems.
@blueyed Ah, I'm sorry, but no: since my earlier post, I've given in and gone back to syntax on
. I should have mentioned this, but didn't think of it. Apologies. (This markdown plugin wasn't the only thing that was wonky without it.)
So something else must be the issue, though I'm not sure what it is.
Output for verb set flp fo ft inde comments tw
:
formatlistpat=^\s*\d\+[\]:.)}\t ]\s*
Last set from /usr/local/Cellar/macvim/7.4-73_1/MacVim.app/Contents/Resources/vim/runtime/ftplugin.vim
formatoptions=tcq
Last set from /usr/local/Cellar/macvim/7.4-73_1/MacVim.app/Contents/Resources/vim/runtime/ftplugin.vim
filetype=mkd
Last set from ~/Dropbox/dotfiles/.vim/bundle/vim-markdown/ftdetect/mkd.vim
indentexpr=GetMkdIndent()
Last set from ~/Dropbox/dotfiles/.vim/bundle/vim-markdown/indent/mkd.vim
comments=s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-
Last set from /usr/local/Cellar/macvim/7.4-73_1/MacVim.app/Contents/Resources/vim/runtime/ftplugin.vim
textwidth=77
formatlistpat=^\s*\d\+[\]:.)}\t ]\s*
formatoptions=croql
Last set from /usr/share/vim/vim73/ftplugin/vim.vim
filetype=vim
Last set from /usr/share/vim/vim73/filetype.vim
indentexpr=GetVimIndent()
Last set from /usr/share/vim/vim73/indent/vim.vim
comments=sO:" -,mO:" ,eO:"",:"
Last set from /usr/share/vim/vim73/ftplugin/vim.vim
textwidth=78
Last set from /usr/share/vim/vim73/ftplugin/vim.vim
set fo
gives me formatoptions=rtcqln
:+1:
formatlistpat=^\s*\d\+\.\s\+\|^[-*+]\s\+
Last set from /usr/share/vim/vim73/ftplugin/markdown.vim
formatoptions=rtcqln
Last set from /usr/share/vim/vim73/ftplugin/markdown.vim
filetype=markdown
Last set from ~/.vimrc
indentexpr=GetMkdIndent()
Last set from ~/Dropbox/Application Support/Dotfiles/.vim/bundle/vim-markdown/indent/mkd.vim
comments=fb:*,fb:-,fb:+,n:>
Last set from /usr/share/vim/vim73/ftplugin/markdown.vim
textwidth=0
This was referenced above but I don't see a reply.
List indent is mentioned in the original spec:
List items may consist of multiple paragraphs. Each subsequent paragraph in a list item must be indented by either 4 spaces or one tab
This allows a markdown parser to bundle multiple paragraphs in one list item. By aligning the text to follow suit you can make the switch to double digit numbers without offsetting the indent as shown:
8. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
9. quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
10. nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
VS
8. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
9. quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
10. nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.
I'm hitting this issue, and found that it's because I remapped <CR>
to <esc>o
(i.e. whereever I am in the line, return starts a new line, rather than splitting the line)
When I removed the mapping, I get the correct list behaviour.
Does that give any clue to the problem? I'd quite like to keep my remapped return key, too...
I worked around by using
inoremap <CR> <esc>A<CR>
formatlistpat=^\s*\d\+\.\s\+\|^[-*+]\s\+
Last set from /usr/share/vim/vim74/ftplugin/markdown.vim
formatoptions=tcqln
Last set from /usr/share/vim/vim74/ftplugin/markdown.vim
filetype=mkd.markdown
Last set from ~/.vim/bundle/vim-markdown/ftdetect/markdown.vim
indentexpr=GetMarkdownIndent()
Last set from ~/.vim/bundle/vim-markdown/indent/markdown.vim
comments=fb:*,fb:-,fb:+,n:>
Last set from /usr/share/vim/vim74/ftplugin/markdown.vim
textwidth=100
Last set from ~/.vimrc
I also am having this issue.
formatlistpat=^\s*\d\+\.\s\+\|^[-*+]\s\+
Last set from /usr/local/Cellar/macvim/7.4-77/MacVim.app/Contents/Resources/vim/runtime/ftplugin
/markdown.vim
formatoptions=tcqln
Last set from /usr/local/Cellar/macvim/7.4-77/MacVim.app/Contents/Resources/vim/runtime/ftplugin
/markdown.vim
filetype=markdown.pandoc
indentexpr=GetMarkdownIndent()
Last set from ~/.vim/bundle/vim-markdown/indent/markdown.vim
comments=fb:*,fb:-,fb:+,n:>
Last set from /usr/local/Cellar/macvim/7.4-77/MacVim.app/Contents/Resources/vim/runtime/ftplugin
/markdown.vim
textwidth=0
I moved some things around in my vimrc and now things are working correctly.
filetype plugin indent on
needs to be above syntax enable
or syntax on
Here is the top of my working vimrc:
execute pathogen#infect()
filetype plugin indent on
syntax enable
Removing filetype plugin indent on
from my vimrc fixed the problem, but that wasn't a good solution.
Alternatively, I was able to fix it by manually issuing :syntax enable
in vim. I thought this was weird because it was already in my vimrc, but eventually I put two and two together.
@arthurdent I think this might be relevant: https://github.com/VundleVim/Vundle.vim/issues/176
It is Vundle not pathogen but I think I recall them both having the same gotcha.
P.S. :+1: on the GitHub username.
@arthurdent moving filetype plugin indent on
did not work for me. Are you sure that was the only change you made? Commenting it out did work however.
FWIW, my :verb set flp fo ft inde comments tw
output:
formatlistpat=^\s*\d\+[\]:.)}\t ]\s*
Last set from ~/.vim/view/~=+.vimrc=
formatoptions=jcroql
Last set from ~/.vim/view/~=+.vimrc=
filetype=vim
Last set from /usr/local/Cellar/neovim/HEAD/share/nvim/runtime/filetype.vim
indentexpr=GetVimIndent()
Last set from ~/.vim/view/~=+.vimrc=
comments=sO:" -,mO:" ,eO:"",:"
Last set from ~/.vim/view/~=+.vimrc=
textwidth=500
Last set from ~/.vim/view/~=+.vimrc=
Also seeing this. What's the solution?
@danawoodman The only other thing I did is disable folding with let g:vim_markdown_folding_disabled=1
, which I also added before syntax enable
. I should definitely mention that using o
or O
to enter insert mode still results in an indent instead of a new item. Only pressing return in insert mode adds an item. I am not sure if this is the intended behavior.
I'm also getting this. The only solution for me was to remove "filetype plugin indent on" from vimrc. : (
This is really, really annoying. I have stayed away from this plugin for years because of this behavior.
I'm using Vim 7.4.258 on OS X.
As a work-around to only disable plugin indents with markdown, I added the following to my .vimrc:
autocmd BufNewFile,BufRead *.md filetype plugin indent off
With the number of people posting in this thread, maybe it should go in the README.md so people find it easier?