When I open a file
:e x
and change its filetype
:set ft=plsql
I can see the effect of setting the filetype because the keywords in the buffer are highlighted according to the filetype (syntax) that I just set.
Then, I open another file
:e y
and switch back to the file where I set the filetype
:e #
the keyword-highlightening is lost, although the filetype is still in effect.
:set ft?
confirms the file type is plsql.
So, how can I make vim so that it keeps the highlighting when I switch back to the file?
I assume you have set nohidden
(or rather, don't have set hidden
). This means, any buffer that is not displayed somewhere is unloaded. Thus, :e y
will make Vim completely forget about x
. When you do :e #
, you don't return to x
: you reload it. Since it's a completely new buffer, your filetype
is, of course, not there.
If you did have set hidden
, opening y
would not unload x
even if it is not being displayed anywhere, and :e #
would simply display the buffer containing x
(which already has the filetype
set). This also has the benefit of making Vim much less annoying, since you can load other files without having to write the current changes to disk (and without the constant pestering from Vim if loading another file when you have unsaved changes is something you really wanted to do).
EDIT: The explanation seems to be bogus. The fix is still set hidden
. Go figure.
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