Vim, how to reload syntax highlighting

VimSyntax Highlightingrails.vim

Vim Problem Overview


When I execute Rmodel, Rcontroller and others in Vim. I see only white text. But when I go to next buffer and then go back by :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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontomekfranekView Question on Stackoverflow
Solution 1 - VimMike LippertView Answer on Stackoverflow
Solution 2 - VimholygeekView Answer on Stackoverflow
Solution 3 - VimJESiiView Answer on Stackoverflow
Solution 4 - VimWormerView Answer on Stackoverflow
Solution 5 - VimCiro Santilli Путлер Капут 六四事View Answer on Stackoverflow
Solution 6 - VimJordanView Answer on Stackoverflow
Solution 7 - VimzenbroView Answer on Stackoverflow