2

When editing markdown (*.md) formatted files, and making bullet points, upon pressing return I want the new bullet point to be automatically created in the same level under the previous one.

Fortunately, :set autoindent does exactly this. However, I shouldn't have to specify it manually according to my ~/.vimrc (note the filetype plugin indent on line and please excuse my horrible config).

I've tested it also with HTML and JavaScript formatted files, and found that autoindent is being applied there.

2

I'm not entirely sure what you mean, but I believe that :set autoindent should do what you expect. From :help 'autoindent':

Copy indent from current line when starting a new line (typing in Insert mode or when using the "o" or "O" command). If you do not type anything on the new line except or CTRL-D and then type , CTRL-O or , the indent is deleted again. Moving the cursor to another line has the same effect, unless the 'I' flag is included in 'cpoptions'.

1

If I understand you correctly, the behavior you want is controlled by the comments and formatoptions options, which are set to comments=fb:*,fb:-,fb:+,n:> and formatoptions=tcqln by $VIMRUNTIME/ftplugin/markdown.vim. Those options are described here:

:help 'comments'
:help format-comments
:help 'formatoptions'
:help fo-table

To have the next line not automatically indented when you press <Return> while entering a bullet, you need to remove the f flag from the * comment definition. The commands to do that without disturbing the other comment definitions are:

:set comments-=fb:*
:set comments+=b:*

To have a bullet inserted automatically when you press Return, formatoptions needs to include the r flag. The command to do that is:

:set formatoptions+=r

You'll need to do those commands after those options have been set by the plugin file, so put those commands, without the leading colons, in a file named `~/.vim/after/ftplugin/markdown.vim.

1

filetype indent on, as the documentation says, loads the corresponding indent file for that filetype. That is, it loads $VIMRUNTIME/indent/<filetype>.vim (and similarly for other directories in runtimepath). And there is none for markdown. Compare (well, even though there's nothing to compare) with indent/go.vim, which does set autoindent:

" C indentation is too far off useful, mainly due to Go's := operator.
" Let's just define our own.
setlocal nolisp
setlocal autoindent
setlocal indentexpr=GoIndent(v:lnum)
setlocal indentkeys+=<:>,0=},0=

So, just using filetype indent on isn't enough, you have to have indent/markdown.vim somewhere in your runtimepath set autoindent. Therefore, create ~/.vim/indent/markdown.vim, containing:

setlocal autoindent

Or just add set autoindent to your vimrc, if it's useful enough across filetypes.

-1

It seems that there is no default vim plugin for md file type. Using vundle I add this plugin and it seems to work well:

gabrielelana/vim-markdown

Which is the found at github: https://github.com/gabrielelana/vim-markdown

To install using vundle add this line in the vundle config section of your .vimrc

Plugin 'gabrielelana/vim-markdown'

To install using pathogen:

cd ~/.vim/bundle && \
git clone git://github.com/gabrielelana/vim-markdown.git
  • 2
    Ehm, Vim comes with markdown support, and has for a very long time... – Martin Tournoij Dec 17 '15 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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