An example of configuring Vim to support Markdown.
Last active
June 21, 2016 20:38
-
-
Save lsloan/b001fdd018c0622169d344ab844b634b to your computer and use it in GitHub Desktop.
My vim environment that does a pretty good job with showing formatting as one edits markdown and keeps my preferred behavior.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" | |
" .vimrc | |
" | |
" Vim configuration resource file. Specifies desired | |
" behavior for the vim editor. | |
" | |
" REQUIRED. This makes vim invoke latex-suite when you open a tex file. | |
filetype plugin on | |
" IMPORTANT: grep will sometimes skip displaying the file name if you | |
" search in a single file. This will confuse latex-suite. Set your grep | |
" program to alway generate a file-name. | |
set grepprg=grep\ -nH\ $* | |
" OPTIONAL: This enables automatic indentation as you type. | |
filetype indent on | |
:set showmode " Tell you if you're in insert mode | |
:set tabstop=3 " Set the tabstop to 3 spaces | |
:set shiftwidth=3 " Shiftwidth should match tabstop | |
:set expandtab " Convert tabs to <tabstop> number of spaces | |
:set nowrap " Do not wrap lines longer than the window | |
:set nowrapscan " Do not wrap to the top of the file while searching | |
:set ruler " Show the cursor position all the time | |
:set showmatch " Show matching [] () {} etc... | |
:set smartindent " Let vim help you with your code indention | |
:set nohlsearch " Don't highlight strings you're searching for | |
:set formatoptions+=ro " Automatically insert the comment character when | |
" you hit <enter> (r) or o/O (o) in a block comment. | |
:set backspace=2 " makes backspace work like you expect | |
:set nu " shows line numbers | |
colorscheme darkblue | |
" Switch syntax highlighting on, when the terminal can support colors | |
if &t_Co > 2 || has("gui_running") | |
:syntax on | |
" Change the highlight color for Comment and Special | |
" to Cyan. Blue is too dark for a black background. | |
:highlight Comment term=bold ctermfg=202 guifg=orange | |
:highlight Special term=bold ctermfg=green guifg=green | |
:highlight Constant term=bold ctermfg=205 guifg=hotpink | |
endif | |
" Make vim turn *off* expandtab for files named Makefile or makefile | |
" We need the tab literal | |
:autocmd BufNewFile,BufRead [Mm]akefile* set noexpandtab | |
" Make vim recognize a file ending in ".template" be a C++ source file | |
:autocmd BufNewFile,BufRead *.template set ft=cpp | |
" Use perl compiler for all *.pl and *.pm files. | |
autocmd BufNewFile,BufRead *.p? compiler perl | |
" Make commenting a little easier | |
vnoremap # :s#^#\## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim syntax file | |
" Language: Markdown | |
" Author: Ben Williams <[email protected]> | |
" Maintainer: Justin Fincher <[email protected]> | |
" Version: 1.0.2 | |
" Last Change: 2014-08-13 | |
" Remark: Added notation for code blocks and additional italics | |
" Remark: Uses HTML syntax file | |
" Remark: I don't do anything with angle brackets (<>) because that would too easily | |
" easily conflict with HTML syntax | |
" TODO: Handle stuff contained within stuff (e.g. headings within blockquotes) | |
" Read the HTML syntax to start with | |
if version < 600 | |
so <sfile>:p:h/html.vim | |
else | |
runtime! syntax/html.vim | |
unlet b:current_syntax | |
endif | |
if version < 600 | |
syntax clear | |
elseif exists("b:current_syntax") | |
finish | |
endif | |
" Don't use standard HiLink, it will not work with included syntax files | |
if version < 508 | |
command! -nargs=+ HtmlHiLink hi link <args> | |
else | |
command! -nargs=+ HtmlHiLink hi def link <args> | |
endif | |
syntax spell toplevel | |
syntax case ignore | |
syntax sync linebreaks=1 | |
" Additions to HTML groups | |
syntax region htmlBold start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\*\@!\S/ end=/\S\\\@<!\*\@<!\*\*\*\@!\($\|\A\)\@=/ contains=htmlItalic,@Spell | |
" Added by Fincher | |
syntax region htmlItalic start=/\\\@<!\(^\|\A\)\@=\~\@<!\~\~\~\@!\S/ end=/\S\\\@<!\~\@<!\~\~\~\@!\($\|\A\)\@=/ contains=htmlItalic,@Spell | |
syntax region htmlItalic start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\@!\S/ end=/\S\\\@<!\*\@<!\*\*\@!\($\|\A\)\@=/ contains=htmlBold,@Spell | |
syntax region htmlItalic start=/\\\@<!\(^\|\A\)\@=\<_\@<!___\@!\S/ end=/\S\\\@<!_\@<!___\@!\($\|\A\)\@=/ contains=htmlBold,@Spell | |
syntax region htmlItalic start=/\\\@<!\(^\|\A\)\@=\<_\@<!__\@!\S/ end=/\S\\\@<!_\@<!__\@!\($\|\A\)\@=/ contains=htmlBold,@Spell | |
" [link](URL) | [link][id] | [link][] | |
syntax region mkdLink matchgroup=mkdDelimiter start="\!\?\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite | |
syntax region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained | |
syntax region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained | |
" Link definitions: [id]: URL (Optional Title) | |
" TODO handle automatic links without colliding with htmlTag (<URL>) | |
syntax region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite | |
syntax region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline | |
syntax region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained | |
syntax region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained | |
syntax region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained | |
" Define Markdown groups | |
syntax match mkdLineContinue ".$" contained | |
syntax match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/ | |
syntax match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/ | |
syntax match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/ | |
syntax match mkdRule /^\s*-\{3,}$/ | |
syntax match mkdRule /^\s*\*\{3,5}$/ | |
syntax match mkdListItem /^\s*[-*+]\s\+.*\n\(\(^.\+\n\)*\n\?\)\(\(^\(\s\{4}\|\t\)\+.*\n\)\(^.\+\n\)*\n\?\)*/ contains=mkdListCode,mkdCode,htmlBold,htmlItalic,htmlSpecialChar | |
syntax match mkdListItem /^\s*\d\+\.\s\+.*\n\(\(^.\+\n\)*\n\?\)\(\(^\(\s\{4}\|\t\)\+.*\n\)\(^.\+\n\)*\n\?\)*/ contains=mkdListCode,mkdCode,htmlBold,htmlItalic,htmlSpecialChar | |
" | |
syntax match mkdBlockCode /^\s*\n\(^\(\s\{4}\|\t\).*\n\)\+/ | |
syntax match mkdListCode /^\s*\n\(^\(\s\{8}\|\t{2}\).*\n\)\+/ | |
syntax match mkdLineBreak / \+$/ | |
syntax region mkdCode start=/\\\@<!`/ end=/\\\@<!`/ | |
syntax region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/ | |
" Added by Fincher | |
syntax region mkdCode start=/\s*```[^`]*/ end=/[^`]*```\s*/ | |
syntax region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell | |
syntax region mkdCode start="<pre[^>]*>" end="</pre>" | |
syntax region mkdCode start="<code[^>]*>" end="</code>" | |
" HTML headings | |
syntax region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell | |
syntax region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell | |
syntax region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell | |
syntax region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell | |
syntax region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell | |
syntax region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell | |
syntax match htmlH1 /^.\+\n=\+$/ contains=@Spell | |
syntax match htmlH2 /^.\+\n-\+$/ contains=@Spell | |
"highlighting for Markdown groups | |
HtmlHiLink mkdString String | |
HtmlHiLink mkdCode String | |
HtmlHiLink mkdListCode String | |
HtmlHiLink mkdBlockCode String | |
HtmlHiLink mkdBlockquote Comment | |
HtmlHiLink mkdLineContinue Comment | |
HtmlHiLink mkdListItem Identifier | |
HtmlHiLink mkdRule Identifier | |
HtmlHiLink mkdLineBreak Todo | |
HtmlHiLink mkdLink htmlLink | |
HtmlHiLink mkdURL htmlString | |
HtmlHiLink mkdID Identifier | |
HtmlHiLink mkdLinkDef mkdID | |
HtmlHiLink mkdLinkDefTarget mkdURL | |
HtmlHiLink mkdLinkTitle htmlString | |
HtmlHiLink mkdDelimiter Delimiter | |
let b:current_syntax = "markdown" | |
delcommand HtmlHiLink | |
" vim: tabstop=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment