You are not logged in.

#1 2009-05-26 17:31:22

miggy
Member
From: MT
Registered: 2007-11-05
Posts: 67

[SOLVED] syntax highlighting in vim

Hi,

How do you guys set syntax highlighting in your vimrc?  For example, I have a bunch of mutt config files saved as something like alias.muttrc, colors.muttc, etc... and I want them all to use the muttrc syntax.

Currently, I have this in my vimrc:

au BufNewFile,BufRead *.muttrc setf muttrc

This works unless my first line is a comment (or first non-blank line).   Which is annoying because I want to begin with a comment sometimes!

Also, I noticed that if my main config file--muttrc--is set correctly whether or not it begins with a comment.   (This file is already matched to muttrc syntax without my intervention).

Does anyone have a better/different way of setting the syntax?

Last edited by miggy (2009-05-27 16:15:44)

Offline

#2 2009-05-26 18:55:08

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: [SOLVED] syntax highlighting in vim

in

~/.vim/ftdetect

put a file named

muttrc.vim

with the contents

au BufNewFile,BufRead *.muttrc setf muttrc

Offline

#3 2009-05-26 21:26:57

miggy
Member
From: MT
Registered: 2007-11-05
Posts: 67

Re: [SOLVED] syntax highlighting in vim

Thanks for the suggestion but I'm experiencing the same behavior.  Something weird's going on.   Can someone confirm this same behavior?

file1.muttrc

color normal white default

file2.muttrc

# Comment
color normal white default

file3.muttrc

color normal white default
# Comment

As I'm writing these, they all are good, but when I go to edit them, only file1.muttrc has the correct highlighting.  The others can get it if I say :set syntax=muttrc. 

It's especially weird that the comments are highlighted but nothing else is.  If I'm not using any sort of file detecting then not even the comments are highlighted

Offline

#4 2009-05-26 21:45:32

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] syntax highlighting in vim

um i just add

# vim: set ft=muttrc:

to the top of all my muttrc.{colors,sig,etc} files.  been working for me.

Offline

#5 2009-05-26 22:22:57

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

Re: [SOLVED] syntax highlighting in vim

@ miggy
Just tried those files with the muttrc.vim of scio.
Works without problems here.

I presume there be some file detection mechanism checking your files for hash marks prior to .vim/ftdetect/muttrc.vim gets a chance.


To know or not to know ...
... the questions remain forever.

Offline

#6 2009-05-27 13:07:28

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: [SOLVED] syntax highlighting in vim

Sorry, I forgot to mention you need to have

filetype plugin on

or

filetype plugin indent on

(for indents as well)
in your .vimrc for the filetype stuff to work.  It's in the default config if you want to start with that as your base.

Edit: added indents since that's what is actually in the default .vimrc

Last edited by scio (2009-05-27 13:08:02)

Offline

#7 2009-05-27 13:27:32

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [SOLVED] syntax highlighting in vim

good catch scio, i have this in my .vimrc:

syntax on
filetype plugin indent on

and an example mutt source file:

# colors for mutt
# source in muttrc
# 256 color support required
# vim: set ft=muttrc:

# set default
color normal white default

which is highlighted correctly simply by vim reading that commented line.

Offline

#8 2009-05-27 14:28:42

miggy
Member
From: MT
Registered: 2007-11-05
Posts: 67

Re: [SOLVED] syntax highlighting in vim

@scio -- I appreciate your help but I haven't noticed any behavior different from my original strategy.  I don't have it totally figured out, but sometimes when I have comments (not even necessarily at the beginning) the highlighting is not correct.  It's fine when I first am writing the file, but not after I open it again for editing.

@brisbin -- Your strategy works but I haven't decided whether or not I want to use it.  I'd rather figure out what is going wrong.

@benarcher -- Thanks for the confirmation.

Offline

#9 2009-05-27 14:49:02

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [SOLVED] syntax highlighting in vim

miggy wrote:

Thanks for the suggestion but I'm experiencing the same behavior.  Something weird's going on.   Can someone confirm this same behavior?

I can confirm the identical behavior, but ':help setf' clued me in.  Apparently setf doesn't set the filetype if it has already been set somewhere else.  Replace it with

autocmd BufRead,BufNewFile *.muttrc set ft=muttrc

which sets the filetype unconditionally.

Offline

#10 2009-05-27 15:32:40

miggy
Member
From: MT
Registered: 2007-11-05
Posts: 67

Re: [SOLVED] syntax highlighting in vim

Perfect!

Thanks Trent!!!

Offline

#11 2009-05-27 15:56:14

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] syntax highlighting in vim

[solved]?

Offline

#12 2009-05-27 16:00:51

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: [SOLVED] syntax highlighting in vim

@Trent: Nice catch! I figured setf was a shortcut for set filetype but it is set ft like you said.

@Miggy: You might want to edit the topic to mark as solved now smile

Offline

Board footer

Powered by FluxBB