How to add Syntax Highlighting in Vim for .ini files
Asked Answered
C

2

8

I recently started using Vi Improved and being a Rainmeter Skin Specialist, when editing my .ini files I can't find a way to add syntax highlight for such files. I searched for a lot of time on stack and git and turned up to nothing. Requesting help at the latest.

TLDR; Need .ini file syntax highlighting for Vim

Checkerbloom answered 22/7, 2021 at 6:6 Comment(2)
I guess file syntax highlighting for .ini already exists. Try set syntax=dosini if Vim has one. Mine is Neovim, so I am not completely sure.Atmolysis
I wanted to highlight Python's poetry.lock file. I just needed set filetype=dosini Thanks @Atmolysis I'm not sure that this lock file is a 100% ini file, but it looks nice.Gerbold
C
11

To force the current file to use ini syntax highlighting:

:set syntax=dosini

The dosini part is the tricky part as it doesn't come to mind. I tried stuff like syntax=ini and started Googling when that didn't work. The top comment on the question answered it, which is the solution above.

Classicism answered 23/11, 2023 at 13:45 Comment(1)
Cool, this worked for me too: Proxmox VE 8.1.4 + empty ~/.vimrc :PRigorism
S
4

Vim already has syntax highlighting for *.ini files.

  • If your Vim is reasonably recent, say 8.0 and up, and you didn't set anything up with regards to Vim (no $HOME\_vimrc, nothing), then your *.ini files should be highlighted without any human intervention at all.

    The screenshot below was taken in a test VM with a basic Vim without any setup:

    vim

  • If you have already customised Vim, with a $HOME\_vimrc file and/or with a $HOME\vimfiles directory, then you are in full control, which means that the automatic stuff described above is no longer done for you anymore. And being in full control of Vim pretty much requires that you learn it properly and configure it as you go.

    Having EITHER of the following lines in your $HOME\_vimrc or $HOME\vimfiles\vimrc is going to give you automatic syntax highlighting for any recognised filetype:

    syntax enable
    syntax on
    
Swagerty answered 22/7, 2021 at 8:39 Comment(1)
OK, I get it, but now I understand that I am currently using vim in kali wsl in windows terminal and all files except .ini highlights automatically even though I have syntax on in my vimrc. Cheers mate and thank youCheckerbloom

© 2022 - 2025 — McMap. All rights reserved.