6

I am opening a file with no extension with vim, say:

myappsetting.conf

This file is actually a *.ini file, with following formats:

[setting_a]
yo = 1234

How can I enable vim to correctly display this file with colour with the correct format?

I am looking for some vim command like:

:set syntaxtype=ini

Thanks.

hllau
  • 9,879
  • 7
  • 30
  • 35

4 Answers4

8

Put this in your .vimrc :

au BufReadPost *.conf set syntax=ini
tUrG0n
  • 4,178
  • 3
  • 20
  • 26
7

I was having the same issue on my Arch linux desktop. I found these files owned by the vim-runtime package.

$ pacman -Qlq vim-runtime | grep dosini
/usr/share/vim/vim74/ftplugin/dosini.vim
/usr/share/vim/vim74/syntax/dosini.vim

Based on that, I found I could get dosini highlighting either by setting the syntax (syn) or the filetype (ft).

:set ft=dosini

You can have this happen automatically with a vim modeline. Add this to the last line of your file.

# vim: set ft=dosini :
carlwgeorge
  • 627
  • 5
  • 13
  • For the modeline to work, though, you have to enable it. Issue `set modeline` in a vim session or (better yet) add `set modeline` to your `~/.vimrc` http://vim.wikia.com/wiki/Modeline_magic – Marcello Romani Feb 18 '15 at 10:54
  • If `modeline` is enabled you can also just use `# vim: ft=dosini` (notice does not require "set" ) and it doesn't need to be the last line - I usually use it as the first line – cwd Nov 16 '16 at 18:25
6

You can try this to reset the syntax:

:set syn=ini
Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
kev
  • 155,172
  • 47
  • 273
  • 272
  • The color still hasn't come up. :-( – hllau Mar 03 '12 at 05:33
  • Do you have a `~/.vim/syntax/ini.vim` file? – kev Mar 03 '12 at 05:35
  • 1
    Type **`:verbose set syn=ini`** to check if there's a error message. – kev Mar 03 '12 at 05:37
  • A file called `abc.ini` would display correctly, but when I rename the file into `abc.conf`, even after the command `:set syn=ini` it does not work. – hllau Mar 03 '12 at 05:39
  • 2
    open `abc.ini` in vim, then type **`:set syn?`** to check the syntax type. – kev Mar 03 '12 at 05:42
  • 1
    Thanks kev. `:verbose set syn=ini` tells me the `ini.vim` file is missing. Interesting though that a regular `*.ini` file would not require `ini.vim` to display correctly. – hllau Mar 03 '12 at 05:43
  • where is the `ini.vim` in your system? In `Windows`, it usually in `C:\Program Files\Vim\vimfiles\syntax` or `C:\Program Files\Vim\vim73\syntax` – kev Mar 03 '12 at 05:47
0

Work for me for *.conf, in .vimrc file:

au BufReadPost *.conf set syntax=dosini
iqmaker
  • 2,162
  • 25
  • 24