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?
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?
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!
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.
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?