When I set tw vim will auto wrap lines at tw. When breaking that line vim usually places some spaces to keep the indentation of the previous line. Example

  bar<suppose that a wrap happens here>
## <- this amount of space is added to keep the line idented

What are the options that control this behavior?

-- edit

To be more precise I was editing markdown and it indents lists this way

- foo bar tar <wrap happens!>
    tick tack

While I expect

- foo bar tar <wrap happens!>
  tick tack

I just don't want to tie the response to markdown so that I can apply it to other formats.

  • 2
    Quite a few: autoindent, smartindent, cindent, indentexpr. Also not to forget copyindent, expandtab and shiftwidth. You may want to look at this question. If something is still unclear, please, make your question more specific.
    – Matt
    Commented Mar 28, 2020 at 16:54
  • I will edit the question
    – geckos
    Commented Mar 28, 2020 at 17:36
  • 1
    When you edit a markdown file... Do you have indentexpr set? What does :set indentexpr? say when you're editing a markdown file... (Wondering if you have a plug-in such as vim-polyglot or vim-markdown or similar installed that might have a particular indent setting for markdown...) In particular, I can't reproduce your indentation issue, maybe try with vim -u NONE -N, then open a markdown file, see if you get the same behavior or not.
    – filbranden
    Commented Mar 28, 2020 at 17:44
  • @filbranden yeah is something in my vimrc, it can be found here github.com/dhilst/dhilst/blob/master/.vimrc. I'm using neovim v0.4.3 on mac.
    – geckos
    Commented Mar 28, 2020 at 19:01
  • The loaded scripts: gist.github.com/dhilst/470f9431e45320ba08f6d31294156357
    – geckos
    Commented Mar 28, 2020 at 19:14

1 Answer 1


There are too many such options to be able to answer this quesion in a general manner. However, they are mostly programming-languages oriented or exotic ones.

In case of a "text document", such as markdown, you likely have to deal with only autoindent (an alternative is smartindent, as si is sometimes set default in some vimrc's, but si is a sort of "universal programming language" indenter, and you should better keep it off for markdown and such). Also note that autoindent is off by default, so you probably have set ai in your vimrc.

There are also several options which influence number / structure of tabs / spaces in an (auto-)indent, but, I guess, it's not the point of your interest right now.

Also speaking of markdown, it's worth to note that there's formatlistpat option (set by ftplugin) to detect "lists". So "the list items" in markdown will get indented even if set noautoindent.

And the last but not least, autoindent will come in play if you have textwidth set. Not wrap and wrapmargin. The point is that textwidth results in adding "real" newlines in your file (and hence autoindent will do its job). While wrapmargin results in "on-screen" wrapping.

  • I have this setting set ts=2 sts=2 sw=2 et on my .vimrc. Also, I don't know why I have ai set. I note that when I press O I got the same behavior, so I think is ai related
    – geckos
    Commented Mar 28, 2020 at 19:05
  • 1
    @geckos I don't know why I have ai set Just do :verbose set ai?
    – Matt
    Commented Mar 28, 2020 at 19:20
  • Nice trick, Last set from ~/.vim/plugged/vim-polyglot/indent/markdown.vim line 8
    – geckos
    Commented Mar 28, 2020 at 19:33
  • 1
    Removing vim-polyglot fixed :D Thanks!
    – geckos
    Commented Mar 28, 2020 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.