Shengjie
Shengjie

Reputation: 12786

vim configuration to turn on syntax for .conf files

I have a config file under my python project, called "logging.conf", the file looks like:

[formatters]
keys: console, logging

[formatter_console]
format: %(asctime)s | %(message)s

[formatter_logging]
format: %(message)s

etc etc etc

Tried :syntax on, nothing happened, the .conf files look very plain. Is there anyway I can turn on some syntax to make the .conf file more colorful and readable?

Upvotes: 28

Views: 21672

Answers (4)

Dev LePeer
Dev LePeer

Reputation: 3

The key issue here is that the syntax in your conf file is usually associated with .ini files. Setting the type (ingo's answer) fixes this issue. Alternatively you could just rename your file.

mv logging.conf logging.ini

echo "syntax on" >> ~/.vimrc

Setting .ini as the file extension maybe more desirable than having custom rules. (I do understand that this may not be possible in all cases)

Upvotes: 0

ji-ruh
ji-ruh

Reputation: 701

I almost have that kind of text style but mine was the ansible hosts file, I found a lot of options here filetype.vim. I used povini or texmf for my ansible hosts file text highlights

To configure it in your .vimrc.

  1. Grab the string before setf, so in case of provini, it is au BufNewFile,BufRead .povrayrc

  2. Replace the last string(.povrayrc) with *.conf

The final config is au BufNewFile,BufRead *.conf for your .vimrc

Upvotes: 1

Kent
Kent

Reputation: 195079

Your file looks plain, it is correct. ( I assume that you have already set conf as the filetype of your current buffer :set ft? to verify).

if you check your $VIMRUNTIME/syntax/conf.vim

you will see, there are three different colors will be shown in a conf file:

  • hi comment, lines starting with #
  • hi string, text wrapped by ' or "
  • and normal text

your current text has no comment, no quoted text. so it shows just in one color.

The file you show (python conf) is actually ini structure. try Ingo's answer.

Upvotes: 5

Ingo Karkat
Ingo Karkat

Reputation: 172590

You can check vim.org or the Internet for a suitable syntax.

As a first approximation, this somewhat looks like DOS / Windows INI files. Vim comes with a syntax for them; try

:setf dosini

If that suits you, you can add a filetype detection rule:

:autocmd BufRead,BufNewFile logging.conf setf dosini

See :help ftdetect for details.

Upvotes: 74

Related Questions