syntax highlight using :e command

7 views
Skip to first unread message

DragonKeeper

unread,
Dec 2, 2008, 7:15:51 PM12/2/08
to vim_use
Hi,

I use nesC's filetype detection, which works fine if I use "vi
filename.nc" to edit a file. However, if I'm already in the vim
environment, and use ":e filename.nc" to open a file, there is no
syntax highlight. I searched a long time but cannot fix it. Could
anybody help me? Thanks!

By the way, I'm using vim 7.2 in Ubuntu 8.10, and the filetype.vim is:
if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
au! BufRead,BufNewFile *.nc setfiletype nesc
augroup END

Tony Mechelynck

unread,
Dec 3, 2008, 3:42:29 PM12/3/08
to vim...@googlegroups.com

That looks all right. Do you have any ":set" command for the
'runtimepath' (or 'rtp') option in your vimrc?

When you use ":e filename" to open a file of a different filetype, it
does get highlighted, doesn't it?


Best regards,
Tony.
--
TALL KNIGHT OF NI: Ni!
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

Charles Campbell

unread,
Dec 3, 2008, 4:18:34 PM12/3/08
to vim...@googlegroups.com
Tony Mechelynck wrote:
> On 03/12/08 01:15, DragonKeeper wrote:
>
>> Hi,
>>
>> I use nesC's filetype detection, which works fine if I use "vi
>> filename.nc" to edit a file. However, if I'm already in the vim
>> environment, and use ":e filename.nc" to open a file, there is no
>> syntax highlight. I searched a long time but cannot fix it. Could
>> anybody help me? Thanks!
>>
>> By the way, I'm using vim 7.2 in Ubuntu 8.10, and the filetype.vim is:
>> if exists("did_load_filetypes")
>> finish
>> endif
>> augroup filetypedetect
>> au! BufRead,BufNewFile *.nc setfiletype nesc
>> augroup END
>>
>
> That looks all right. Do you have any ":set" command for the
> 'runtimepath' (or 'rtp') option in your vimrc?
>
> When you use ":e filename" to open a file of a different filetype, it
> does get highlighted, doesn't it?
>

Hmm -- au! clears autocmds from the containing augroup. Perhaps you
should try

...
augroup filetypedetect
au BufRead,BufNewFile *.nc setfiletype nesc
augroup END

Regards,
Chip Campbell

DragonKeeper

unread,
Dec 11, 2008, 5:33:32 PM12/11/08
to vim_use
I didn't set any 'runtimepath' or 'rtp' option. And it does get
hightlighted when opening other type files.

On Dec 3, 2:42 pm, Tony Mechelynck <antoine.mechely...@gmail.com>
wrote:
> On 03/12/08 01:15, DragonKeeper wrote:
>
> > Hi,
>
> > I usenesC'sfiletype detection, which works fine if I use "vi

DragonKeeper

unread,
Dec 11, 2008, 5:34:08 PM12/11/08
to vim_use
No, it doesn't help.

On Dec 3, 3:18 pm, Charles Campbell <Charles.E.Campb...@nasa.gov>
wrote:
> Tony Mechelynck wrote:
> > On 03/12/08 01:15, DragonKeeper wrote:
>
> >> Hi,
>
> >> I usenesC'sfiletype detection, which works fine if I use "vi

Ben Schmidt

unread,
Dec 11, 2008, 5:54:38 PM12/11/08
to vim...@googlegroups.com
>>> Hi,
>>> I usenesC'sfiletype detection, which works fine if I use "vi
>>> filename.nc" to edit a file. However, if I'm already in the vim
>>> environment, and use ":e filename.nc" to open a file, there is no
>>> syntax highlight. I searched a long time but cannot fix it. Could
>>> anybody help me? Thanks!
>>> By the way, I'm using vim 7.2 in Ubuntu 8.10, and the filetype.vim is:
>>> if exists("did_load_filetypes")
>>> finish
>>> endif
>>> augroup filetypedetect
>>> au! BufRead,BufNewFile *.nc setfiletype nesc
>>> augroup END

> I didn't set any 'runtimepath' or 'rtp' option. And it does get


> hightlighted when opening other type files.

Please bottom-post, DragonKeeper, particularly if somebody already has,
or things get very confusing (posting guidelines are here:
http://groups.google.com/group/vim_use/web/vim-information
).

It is correct that you probably don't want the bang (!) on your
autocommand, but I doubt that will cause the problem.

You can check both autocommand events have been registered in Vim with

:au * *.nc

Assuming this shows two entries as expected, each saying setfiletype
nesc, I suspect the problem is not the autocommand but something in the
highlighting script. Could you share that (presumably nesc.vim)?

Another thing you can do to see what's going on is do

:set verbose=2 " or 10 or 15 for more details
:e whatever.nc
:set verbose=0

and see if that helps track things down.

Ben.

DragonKeeper

unread,
Dec 12, 2008, 12:18:32 PM12/12/08
to vim_use
Hi Ben,

I use ":au * *.nc" to check autocommand events, but there is nothing.
After that, I set the verbose and the following is the output:

"PlatformSerialC.nc" 21L, 417C
Reading viminfo file "/home/xin/.viminfo" marks
Searching for "scripts.vim" in "/home/xin/.vim,/var/lib/vim/addons,/
usr/share/vi
m/vimfiles,/usr/share/vim/vim71,/usr/share/vim/vimfiles/after,/var/lib/
vim/addon
s/after,/home/xin/.vim/after"
Searching for "/home/xin/.vim/scripts.vim"
Searching for "/var/lib/vim/addons/scripts.vim"
Searching for "/usr/share/vim/vimfiles/scripts.vim"
Searching for "/usr/share/vim/vim71/scripts.vim"
line 0: sourcing "/usr/share/vim/vim71/scripts.vim"
finished sourcing /usr/share/vim/vim71/scripts.vim
continuing in BufRead Auto commands for "*"
Searching for "/usr/share/vim/vimfiles/after/scripts.vim"
Searching for "/var/lib/vim/addons/after/scripts.vim"
Searching for "/home/xin/.vim/after/scripts.vim"

I think "continuing in BufRead Auto commands for "*"" is not right.

BTW, I didn't write the nesc.vim by myself. the script coming with
TinyOS is:

1 " Install this file to ~/.vim/syntax/nesc.vim.
2
3 runtime! syntax/c.vim
4 let b:current_syntax = "nesc"
5
6 syn keyword cStatement abstract as async atomic call
command
7 syn keyword cStatement components configuration event
generic
8 syn keyword cStatement implementation includes interface
module
9 syn keyword cStatement new norace post provides signal
task unique
10 syn keyword cStatement uniqueCount uses
11
12 syn keyword cType result_t error_t
13
14 syn keyword cConstant SUCCESS FAIL TRUE FALSE

I installed it in ~/.vim/plugin/nesc.vim.

On Dec 11, 4:54 pm, Ben Schmidt <mail_ben_schm...@yahoo.com.au> wrote:
> >>> Hi,
> >>> I usenesC'sfiletype detection, which works fine if I use "vi
> >>> filename.nc" to edit a file. However, if I'm already in the vim
> >>> environment, and use ":e filename.nc" to open a file, there is no
> >>> syntax highlight. I searched a long time but cannot fix it. Could
> >>> anybody help me? Thanks!
> >>> By the way, I'm using vim 7.2 in Ubuntu 8.10, and the filetype.vim is:
> >>>    if exists("did_load_filetypes")
> >>>      finish
> >>>    endif
> >>>    augroup filetypedetect
> >>>      au! BufRead,BufNewFile *.nc   setfiletypenesc
> >>>    augroup END
> > I didn't set any 'runtimepath' or 'rtp' option. And it does get
> > hightlighted when opening other type files.
>
> Please bottom-post, DragonKeeper, particularly if somebody already has,
> or things get very confusing (posting guidelines are here:http://groups.google.com/group/vim_use/web/vim-information
> ).
>
> It is correct that you probably don't want the bang (!) on your
> autocommand, but I doubt that will cause the problem.
>
> You can check both autocommand events have been registered in Vim with
>
> :au * *.nc
>
> Assuming this shows two entries as expected, each saying setfiletypenesc, I suspect the problem is not the autocommand but something in the

Ben Schmidt

unread,
Dec 12, 2008, 8:37:33 PM12/12/08
to vim...@googlegroups.com
Hi, DragonKeeper,

Please write your replies under a short-relevant quote like I am doing.
This is called 'bottom-posting' and is the convention on this mailing
list.

> I use ":au * *.nc" to check autocommand events, but there is nothing.

OK. So something has gone wrong with registering the autocommand.

The snippet you had for 'filetype.vim' should be in ~/.vim/filetype.vim:

if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
au! BufRead,BufNewFile *.nc setfiletype nesc
augroup END

You also need to have

:filetype on
:syntax enable

or something similar to that in your ~/.vimrc.

Make sure you have both those things, and then check that if you do

:au * *.nc

then indeed you do get two commands listed. Until that is sorted out, it
won't work.

> After that, I set the verbose and the following is the output:

Your results are consistent with the autocommand not being registered.

> BTW, I didn't write the nesc.vim by myself. the script coming with
> TinyOS is:
>
> 1 " Install this file to ~/.vim/syntax/nesc.vim.
>

> I installed it in ~/.vim/plugin/nesc.vim.

You need to install it in ~/.vim/syntax/nesc.vim like it says. Note
'syntax' not 'plugin'. You may need to create that directory. That
explains why it works when Vim starts up (which is when it reads
plugins) but not for other files (when it detects filetypes and loads
syntax).

Ben.

DragonKeeper

unread,
Dec 14, 2008, 10:25:08 AM12/14/08
to vim_use
The problem is solved. Thank you, Ben! I learned a lot.

On Dec 12, 7:37 pm, Ben Schmidt <mail_ben_schm...@yahoo.com.au> wrote:
> Hi, DragonKeeper,
>
> Please write your replies under a short-relevant quote like I am doing.
> This is called 'bottom-posting' and is the convention on this mailing
> list.
>
> > I use ":au * *.nc" to check autocommand events, but there is nothing.
>
> OK. So something has gone wrong with registering the autocommand.
>
> The snippet you had for 'filetype.vim' should be in ~/.vim/filetype.vim:
>
>      if exists("did_load_filetypes")
>        finish
>      endif
>      augroup filetypedetect
>        au! BufRead,BufNewFile *.nc   setfiletypenesc
>      augroup END
>
> You also need to have
>
>      :filetype on
>      :syntax enable
>
> or something similar to that in your ~/.vimrc.
>
> Make sure you have both those things, and then check that if you do
>
>      :au * *.nc
>
> then indeed you do get two commands listed. Until that is sorted out, it
> won't work.
>
> > After that, I set the verbose and the following is the output:
>
> Your results are consistent with the autocommand not being registered.
>
> > BTW, I didn't write thenesc.vim by myself. the script coming with
Reply all
Reply to author
Forward
0 new messages