GitHub - preservim/vim-markdown: Markdown Vim Mode (original) (raw)

Vim Markdown

Vint Vader

Syntax highlighting, matching rules and mappings for the original Markdown and extensions.

  1. Installation
  2. Basic usage
  3. Options
  4. Mappings
  5. Commands
  6. Credits
  7. License

Installation

If you use Vundle, add the following lines to your ~/.vimrc:

Plugin 'godlygeek/tabular' Plugin 'preservim/vim-markdown'

The tabular plugin must come before vim-markdown.

Then run inside Vim:

:so ~/.vimrc :PluginInstall

If you use Pathogen, do this:

cd ~/.vim/bundle git clone https://github.com/preservim/vim-markdown.git

To install without Pathogen using the Debian vim-addon-manager, do this:

git clone https://github.com/preservim/vim-markdown.git cd vim-markdown sudo make install vim-addon-manager install markdown

If you are using a package manager with semver support (like lazy.nvim) make sure you are following the master branch (see #616).

If you are not using any package manager, download the tarball and do this:

cd ~/.vim tar --strip=1 -zxf vim-markdown-master.tar.gz

Basic usage

Folding

Folding is enabled for headers by default.

The following commands are useful to open and close folds:

Options are available to disable folding or change folding style.

Try :help fold-expr and :help fold-commands for details.

Concealing

Concealing is set for some syntax such as bold, italic, code block and link.

Concealing lets you conceal text with other text. The actual source text is not modified. If you put your cursor on the concealed line, the conceal goes away.

Options are available to disable or change concealing.

Try :help concealcursor and :help conceallevel for details.

Options

Disable Folding

let g:vim_markdown_folding_disabled = 1  

This option only controls Vim Markdown specific folding configuration.
To enable/disable folding use Vim's standard folding configuration.

Change fold style

let g:vim_markdown_folding_style_pythonic = 1  

g:vim_markdown_folding_level setting (default 1) is set to foldlevel. Thus level 1 heading which is served as a document title is expanded by default.

let g:vim_markdown_override_foldtext = 0  

Set header folding level

let g:vim_markdown_folding_level = 6  

Tip: it can be changed on the fly with:

:let g:vim_markdown_folding_level = 1  
:edit  

Disable Default Key Mappings

let g:vim_markdown_no_default_key_mappings = 1  

You can also map them by yourself with <Plug> mappings.

Enable TOC window auto-fit

let g:vim_markdown_toc_autofit = 1  

Text emphasis restriction to single-lines

let g:vim_markdown_emphasis_multiline = 0  

Syntax Concealing

let g:vim_markdown_conceal = 0  

To disable math conceal with LaTeX math syntax enabled, add the following to your .vimrc:

let g:tex_conceal = ""  
let g:vim_markdown_math = 1  
let g:vim_markdown_conceal_code_blocks = 0  

Fenced code block languages

let g:vim_markdown_fenced_languages = ['csharp=cs']  

This will cause the following to be highlighted using the cs filetype syntax.
Default is ['c++=cpp', 'viml=vim', 'bash=sh', 'ini=dosini'].

Follow named anchors

let g:vim_markdown_follow_anchor = 1  

This tells vim-markdown whether to attempt to follow a named anchor in a link or not. When it is 1, and only if a link can be split in two parts by the pattern '#', then the first part is interpreted as the file and the second one as the named anchor. This also includes urls of the form #anchor, for which the first part is considered empty, meaning that the target file is the current one. After the file is opened, the anchor will be searched.
Default is 0.

let g:vim_markdown_anchorexpr = "'<<'.v:anchor.'>>'"  

This expression will be evaluated substituting v:anchor with a quoted string that contains the anchor to visit. The result of the evaluation will become the real anchor to search in the target file. This is useful in order to convert anchors of the form, say, my-section-title to searches of the form My Section Title or <<my-section-title>>.
Default is ''.

Syntax extensions

The following options control which syntax extensions will be turned on. They are off by default.

LaTeX math

let g:vim_markdown_math = 1  

YAML Front Matter

let g:vim_markdown_frontmatter = 1  

TOML Front Matter

let g:vim_markdown_toml_frontmatter = 1  

JSON Front Matter

let g:vim_markdown_json_frontmatter = 1  

Strikethrough

let g:vim_markdown_strikethrough = 1  

Adjust new list item indent

let g:vim_markdown_new_list_item_indent = 2  

let g:vim_markdown_no_extensions_in_markdown = 1  

This is super useful for GitLab and GitHub wiki repositories.
Normal behaviour would be that vim-markup required you to do this [link text](link-url.md), but this is not how the Gitlab and GitHub wiki repositories work. So this option adds some consistency between the two.

let g:vim_markdown_autowrite = 1  

Change default file extension

let g:vim_markdown_auto_extension_ext = 'txt'  

Do not automatically insert bulletpoints

let g:vim_markdown_auto_insert_bullets = 0  

In that case, you probably also want to set the new list item indent to 0 as well, or you will have to remove an indent each time you add a new list item:

let g:vim_markdown_new_list_item_indent = 0  

Change how to open new files

let g:vim_markdown_edit_url_in = 'tab'  

Borderless tables

header 1|header 2  
--|--  
data 1|data 2  

if set to 1:

let g:vim_markdown_borderless_table = 1  

the table would be formatted as usual:

| header 1 | header 2 |  
|----------|----------|  
| data 1   | data 2   |  

Mappings

The following work on normal and visual modes:

[Example](http://example.com)  
^  ^    ^^   ^       ^  
1  2    34   5       6  
<http://example.com>  
^  ^               ^  
1  2               3  

Known limitation: does not work for links that span multiple lines.

This plugin follows the recommended Vim plugin mapping interface, so to change the map ]u to asdf, add to your .vimrc:

map asdf <Plug>Markdown_MoveToParentHeader

To disable a map use:

map <Plug> <Plug>Markdown_MoveToParentHeader

Commands

The following requires :filetype plugin on.

Credits

The main contributors of vim-markdown are:

If you feel that your name should be on this list, please make a pull request listing your contributions.

License

The MIT License (MIT)

Copyright (c) 2012 Benjamin D. Williams

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.