Vim, how to reload syntax highlighting
VimSyntax Highlightingrails.vimVim Problem Overview
When I execute Rmodel, Rcontroller and others :bn
and :bl
, colors are working.
This is my .vim folder https://github.com/regedarek/dotvim
Vim Solutions
Solution 1 - Vim
Use :syntax sync fromstart
I got that tip from http://vim.wikia.com/wiki/Fix_syntax_highlighting
That article also suggests creating a mapping for that command e.g. to map F12:
noremap <F12> <Esc>:syntax sync fromstart<CR>
inoremap <F12> <C-o>:syntax sync fromstart<CR>
Solution 2 - Vim
Try:
:e
If you have no unsaved changes to the file.
Or:
:syn off | syn on
Solution 3 - Vim
Tried all the above - none worked for me.
The only thing that does work is:
:filetype detect
so I remapped a quick shortcut
:noremap <Leader>,ftd :filetype detect
Solution 4 - Vim
Sometimes syntax is OK, but all that is getting broken are foldings. In that case zx
helps alot.
From VIM documentation:
> zx > > Update folds: Undo manually opened and closed folds: re-apply > 'foldlevel', then do "zv": View cursor line. > Also forces recomputing folds. This is useful when using > 'foldexpr' and the buffer is changed in a way that results in > folds not to be updated properly.
Solution 5 - Vim
Another option is:
doautocmd Syntax
Solution 6 - Vim
You can also try:
CTRL-L
From the VIM docs (:h CTRL-L
):
> Clear and redraw the screen. The redraw may happen later, after processing typeahead.
Solution 7 - Vim
Try:
:Rrefresh!
This command refresh certain cached settings and also reload rails.vim.
It's help me refresh syntax highlighting in Rails.