You could try putting it in an ftplugin; putting the command in ~/.vim/after/ftplugin/markdown.vim
will define your highlight group after the color scheme is loaded on startup.
However, this may break when changing color schemes because color schemes will typically call :highlight clear
to clear any previously defined highlight groups before defining their own. This can cause user highlight groups defined in .vimrc
to be overridden.
To remedy this, you can create an autocommand that will execute a command every time a color scheme is loaded, but you'll need to check the filetype
of the current buffer.
So, replace
set spelllang=en_us
hi SpellBad cterm=underline
in your .vimrc
with
augroup UnderlineSpell
autocmd!
autocmd ColorScheme * if &ft ==? 'markdown'
\| highlight SpellBad cterm=underline
\| set spelllang=en_us
\| endif
augroup END
It's important to wrap the autocommand in an augroup
to prevent defining the autocommand more than once (if you were to change color schemes, for example). autocmd!
is used to clear any existing autocommands defined for the current augroup
.
There's also a very informative GitHub gist about overriding color schemes in this way that would be a good read.
Also see the following help pages:
vim startup
autocommands
highlight and spelling
~/.vim/after/ftplugin/markdown.vim
hi
command for the buffer.~/.vim/after/ftplugin
and not~/.vim/ftplugin
? It's possible a color scheme is clearing the highlight group.autocmd Colorscheme * highlight SpellBad cterm=underline
(replace the*
if you want to be more specific, and as always wrap in anaugroup
)