Thursday, January 31, 2013

Re: Syntax highlight not happening on :newtab

On 2013-01-30, naaj_ila wrote:
> In my home directory
> "verilog.vim" file is there, which defines syntax highlighting whnever we
> will open <filename>.v files.
> In .vimrc , i added "source ~/verilog.vim" .
>
> Example: file1.v
> module test ;
> $display("Hello");
> endmodule
>
> "module", "display" are keywords and they will be in colour/highlighted .
>
> Whenever a single file(say file1.v) is opened , its working fine (syntax
> highlight is working)
>
>
> whne i opened another file(file2.v) in the file1.v using ":sp file2.v" or
> ":newtab file2.v"
> For file2.v syntax highlight is not enabled/working , file1.v syntax is
> still OK.

Syntax files such as your verilog.vim contain :syntax commands that
assign colors to patterns. The scope of those :syntax commands is
the current buffer. (I can't find that in the documentation.) When
you open a new buffer, the :syntax commands from the original buffer
are not applied to the new buffer.

When you start vim to open a file, the "source ~/verilog.vim"
command in your ~/.vimrc executes a number of :syntax commands that
apply colors to the contents of that first buffer. When you open
another file, that file is opened into a new buffer that has no
:syntax commands applied to it, so you see no colors.

The problem is that you are not using Vim's syntax highlighting
facility as it was designed to be used. You are throwing commands
into your ~/.vimrc and hoping for the best. You should probably
read

:help usr_06.txt
:help usr_43.txt

To fix this problem, you need to:

1. Move ~/verilog.vim to ~/.vim/syntax/verilog.vim where it
belongs;

2. Remove the "source ~/verilog.vim" command from your ~/.vimrc;

3. Add to your ~/.vimrc the command "syntax on".

Vim already knows that the .v suffix means that the file type is
verilog.

HTH,
Gary

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: