I write quite a lot of Markdown on a daily or weekly basis. From meeting notes to documentation — most of the stuff I write for work that’s not code starts in Markdown. I used to use Byword, but it’s another app to switch between. After the last MacBook refresh, there were a few apps I installed immediately and it has pretty much stayed that way.

I’ve been using Vim to edit Markdown, which is fine, but was missing some things. So, I went hunting for the proper vimscript to enable things like soft line-wrapping and spell check. Needless to say, you can do more than that.

Goyo

One of the first things I found way Goyo. Goyo does “distraction-free writing in Vim” and does most of the work — disabling line numbers, vim-airline, soft-wrapping text at 80 characters, and centering it in the terminal window. You have to enable it with :Goyo after you open Vim, but I always want it enabled when I’m editing Markdown, so I wrote some vimscript:

" Goyo
function! s:auto_goyo()
    if &ft == 'markdown' && winnr('$') == 1
        Goyo 80
    elseif exists('#goyo')
        Goyo!
    endif
endfunction

function! s:goyo_leave()
    if winnr('$') < 2
        silent! :q
    endif
endfunction

augroup goyo_markdown
    autocmd!
    autocmd BufNewFile,BufRead * call s:auto_goyo()
    autocmd! User GoyoLeave nested call goyo_leave()
augroup END

vim-markdown

Next, I installed vim-markdown for syntax highlighting. Since most of my Markdown files have the .md extension, I need to tell Vim to treat them as Markdown.

autocmd BufNewFile,BufReadPost *.md set filetype=markdown

One of the vim-markdown features is to allow highlighting of other languages in code blocks:

let g:markdown_fenced_languages = ['javascript', 'go', 'php']

Spell Check

And, finally, I enabled spell checking in ~/.vim/ftplugin/markdown.vim with:

" Spell check
setlocal spell
highlight clear SpellBad
highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline