Friday, February 1, 2013

Re: VIM loses syntax highlighting when using split command

On 2013-02-01, naaj_ila wrote:
> Hi Gary ,
> Its working fine
> i added these things in ~/.vim/syntax/filetype.vim
>
> augroup filetypedetect
> au! BufRead,BufNewFile *.v so ~/.vim/syntax/verilog.vim
> augroup END
>
>
> Working fine from now

How does putting that in ~/.vim/syntax/filetype.vim help you? That
file should be sourced by vim only when you open a file whose file
type is filetype.

While your solution may work in this instance, it is not the
standard way of doing these things. If your version of vim does not
automatically detect verilog files, a proper solution is to put
something like this

augroup filetypedetect
au! BufRead,BufNewFile *.v setfiletype verilog
augroup END

in ~/.vim/filetype.vim. Vim will then take care of sourcing
~/.vim/syntax/verilog.vim for you if you have "syntax on". It will
also source any other verilog plugins such as
~/.vim/ftplugin/verilog.vim if you have an appropriate "filetype on"
command in your ~/.vimrc. See

:help new-filetype

There is nothing wrong with doing things a non-standard way as long
as you know what you're doing. If you're not sure what you're
doing, or you seem to be having difficulty in getting something to
work, it is better to follow the standard methods as you will have
fewer problems and it will be easier for others to help you.

> -----------------------------------------------------
> I need one more help
>
> Whenever , i wanted to open VIm in new buffer via (sp and tabnew ) , i need
> to source one command
>
> :let b:match_words =
> '\<begin\>:\<end\>,'.'\<class\>:\<endclass\>,'.'\<task\>:\<endtask\>,'.'\<case\>:\<endcase\>'
>
> How can i do that
> I added thsi one in .vimrc. Its working only for one file but not in split
> files

It's not working for any but the first file you open because
b:match_words is a buffer-local variable. See

:help buffer-variable

The setting of b:match_words should be done in a filetype plugin so
that it is done for every buffer of that filetype. In this case, it
should be put in ~/.vim/ftplugin/verilog.vim or
~/.vim/after/ftplugin/verilog.vim.

This is a good example of why your autocommand above should set the
filetype to verilog instead of sourcing your syntax file. If you
set the filetype properly, things like filetype plugins just work.

Regards,
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: