I'm using the css_color.vim plugin to highlight CSS hexadecimal color codes with the actual color. It's a bit distracting to have the highlighting turned on all the time so I am wondering if there is any way to toggle a syntax plugin on and off.
If you want to toggle this on/off (without creating a . vimrc file) simply type :syntax on while in vi/vim. Save this answer.
VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.
The runtimepath option contains a list of paths, separated by commas, where vim looks for plugins, syntax files, etc. On unix, the first path is $HOME/. vim/ (aka ~/. vim/ ), which means that Vim looks for syntax files in your home folder first before it looks anywhere else.
Create new syntax instead.
Put the file in .vim/syntax/css_color.vim
and add runtime syntax/css.vim
at the top. Now it acts like its own syntax definition that happens to inherit the base CSS syntax.
When you want CSS with smart colors, use :setf css_color
. When you want to back to stock CSS, :setf css
.
edit: To bind a key:
function! ToggleCssColor()
if &filetype == 'css'
setf css_color
else
setf css
endif
endfunction
noremap <Leader>c :call ToggleCssColor()<CR>
Then \c will switch between the two styles in normal mode. You can set the key to whatever you want, use inoremap
to bind a key in insert mode, etc.
Have a look at alternative plugins. I use colorizer - Highlight #rrggbb or #rgb color, because it has advanced features, works not just for CSS, and can be turned on/off easily.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With