I loose Syntax Colors when switching between Buffers

529 views
Skip to first unread message

analogsix

unread,
Dec 19, 2012, 2:48:19 PM12/19/12
to vim...@googlegroups.com
I have issues with my Vim 7.0 at work.

I edit Verilog RTL files. When I initially load a new buffer/file on gVim, the Syntax highlighting works correctly. When I run a 'force re-edit' (through :edit!) or open an existing buffer (i.e. :edit existing_alternate_file) the syntax highlighting is lost.

In other words:
It appears that when loading a New Buffer, gVim runs the correct sequence of syntax scripts needed to load the Verilog syntax coloring. But gVim chokes when I switching between existing buffers.

Can anyone assist?

Ben Fritz

unread,
Dec 19, 2012, 3:31:58 PM12/19/12
to vim...@googlegroups.com

How are you setting the syntax? Do you have automatic filetype detection turned on (correct), or do you just set the filetype/syntax in your .vimrc?

What exact command do you use to open a new buffer/file so that you see the highlighting?

analogsix

unread,
Dec 20, 2012, 12:49:16 PM12/20/12
to vim...@googlegroups.com
My .gvimrc resource file only contains a few custom modifications like:
set ...
set guifont=...
highlight Normal guibg=black
colorscheme slate
noremap ...


I believe I have the default automatic filetype and syntax coloring VIM configuration settings, since there are no syntax-relevant commands in my .gvimrc resource file.

Scenario1 When Observing the Problem:
say I run gvim file1.sv on the command-line
Then, within gVIM, I run :edit file2.sv
In both cases, syntax coloring is fine.
-
Now, I switch back to file1 by running :edit # (i.e. load alternate buffer)
Now, I loose all my syntax coloring for file1.sv.
Just for kicks, I switch back to file2.sv by running :edit #file2.sv
Now I loose syntax coloring for file2.sv

Interestingly, let's say I load my .gvimrc file in gVim via the command-line and then load file1.sv (i.e. :edit file1.sv) and then switch back to my .gvimrc (i.e. :edit #). In this scenario, I do not loose the syntax coloring for the active .gvimrc file. However, when I switch back to file1.sv, voila... syntax coloring is gone!

Gary Johnson

unread,
Dec 20, 2012, 1:05:16 PM12/20/12
to vim...@googlegroups.com
I don't see any filetype detection rules for *.sv in
$VIMRUNTIME/filetype.vim in my Vim 7.3.646 installation. Perhaps
you're using some custom filetype detection rules that are
incomplete.

When you first load file1.sv and syntax highlighting is working as
you expect it to, what is the result of this command?

:verbose set ft?

Regards,
Gary

analogsix

unread,
Dec 20, 2012, 2:23:10 PM12/20/12
to vim...@googlegroups.com, gary...@spocom.com
result of running that command is:
filetype=

You hit the nail on the head. Namely, when the buffer(s) are first loaded onto gVIM, the filetype(s) aren't recognized (as we can see the 'filetype' option is set to blank).

As a quick fix to get gVIM to properly load and recognize my *.sv files, I've entered the following in my .gvimrc file:
au BufNewFile,BufRead *sv,*svi setf verilog
Now when I load new or toggle existing buffers, syntax coloring works fine.

Going back to the stated problem. How do I explain how the file1.sv syntax was correctly identified and syntax-colored by VIM when initially loaded? Well, my own answer comes from something I recall reading the help file from ":help syntax". I read somewhere in that {m,h}aze of a help file, that during the syntax-loading procedure, if VIM fails at loading syntax settings via its conventional syntax-loading procedure, it scans the file to identify what syntax settings to apply. I guess this VIM feature only works on `loading` ONE new file from the command-line or gVIM, and not on loading multiple new buffers (from the command-line) nor on toggling VIM window views between non-active buffers.

I'm still trying to figure out the details so that I can correctly co-integrate a custom systemverilog.vim syntax file into my .gvimrc. Note that somewhere in the ':help syntax' help file, it states that it's possible to subsume a subset syntax into a superset syntax file (e.g. :source c.vim can be included in $VIMRUNTIME/syntax/cpp.vim)

To be Continued once I piece together some of the :help file info and view some examples.

Gary Johnson

unread,
Dec 20, 2012, 3:04:51 PM12/20/12
to vim...@googlegroups.com
On 2012-12-20, analogsix wrote:
> result of running that command is:
> filetype=
>
> You hit the nail on the head. Namely, when the buffer(s) are first
> loaded onto gVIM, the filetype(s) aren't recognized (as we can see
> the 'filetype' option is set to blank).
>
> As a quick fix to get gVIM to properly load and recognize my *.sv
> files, I've entered the following in my .gvimrc file: au
> BufNewFile,BufRead *sv,*svi setf verilog Now when I load new or
> toggle existing buffers, syntax coloring works fine.
>
> Going back to the stated problem. How do I explain how the
> file1.sv syntax was correctly identified and syntax-colored by VIM
> when initially loaded? Well, my own answer comes from something I
> recall reading the help file from ":help syntax". I read somewhere
> in that {m,h}aze of a help file, that during the syntax-loading
> procedure, if VIM fails at loading syntax settings via its
> conventional syntax-loading procedure, it scans the file to
> identify what syntax settings to apply. I guess this VIM feature
> only works on `loading` ONE new file from the command-line or
> gVIM, and not on loading multiple new buffers (from the
> command-line) nor on toggling VIM window views between non-active
> buffers.

Something doesn't add up here. Syntax files are named according to
the filetype, so for example ft=sh results in the loading of
syntax/sh.vim. If 'ft' is empty, then Vim has no filetype from
which to construct a syntax file name.

Here's the procedure you were referring to:

$VIMRUNTIME/filetype.vim defines a set of rules for determining a
file's filetype from its suffix or extension. If that fails, Vim
tries to determine the filetype from the file's content according to
the rules in $VIMRUNTIME/scripts.vim. (That's a simplification, but
close enough for now.)

Still, Vim cannot automatically apply syntax highlighting without a
filetype.

You might try this command,

:echo b:current_syntax

to see the name of the syntax currently in effect, or rather, last
applied, and this command

:scriptnames

to see which scripts, including syntax highlighting files, have been
sourced.

Those may shed some light on which syntax highlighting you're seeing
and how it was set.

One other thing: If you're sure of what you're doing, you can put
filetype-detection autocommands any place you like. If you're not
sure though, or if you're having difficulty getting things working
the way you think they should, you should probably stick to the
recommended methods for filetype detection described in ":help
new-filetype". The method described under ":help ftdetect" is
probably the simplest.

Regards,
Gary

李季

unread,
Dec 20, 2012, 9:29:20 PM12/20/12
to vim...@googlegroups.com, gary...@spocom.com
I encounter the same problem.
>--
>You received this message from the "vim_use" maillist.
>Do not top-post! Type your reply below the text you are replying to.
>For more information, visit http://www.vim.org/maillist.php

Ben Fritz

unread,
Dec 23, 2012, 10:59:47 AM12/23/12
to vim...@googlegroups.com
On Thursday, December 20, 2012 11:49:16 AM UTC-6, analogsix wrote:
> My .gvimrc resource file only contains a few custom modifications like:
> set ...
> set guifont=...
> highlight Normal guibg=black
> colorscheme slate
> noremap ...
>
>
> I believe I have the default automatic filetype and syntax coloring VIM configuration settings, since there are no syntax-relevant commands in my .gvimrc resource file.
>

There ARE no default automatic filetype and syntax coloring. You need to turn them on like this in your .vimrc:

filetype on
syntax on

Or this:

filetype indent plugin on
syntax on

You listed a few generalizations from your .gvimrc but did not mention your .vimrc? What's in there? And do your "few custom modifications" which include some "set" commands ever touch the filetype option?

Reply all
Reply to author
Forward
0 new messages