Vim Tips Wiki

Dosini files

1,624pages on
this wiki
Add New Page
Talk0 Share
Tip 1514 Printable Monobook Previous Next

created 2007 · complexity basic · version 6.0

Many programs store configuration information in text files with .ini extension ("dosini" file type). An example of a section from an ini file is:


Vim includes file syntax/dosini.vim for syntax highlighting. This tip shows two enhancements: Folding sections, and correct highlighting when heredoc-style parameters are used.

Folding sectionsEdit

You can enable folding of dosini sections by placing a script in file ~/.vim/after/syntax/dosini.vim on Unix-based systems, or in file $HOME/vimfiles/after/syntax/dosini.vim on Windows systems.

The script should contain:

syn region dosiniSection start="^\[" end="\(\n\+\[\)\@=" contains=dosiniLabel,dosiniHeader,dosiniComment keepend fold
setlocal foldmethod=syntax
" Following opens all folds (remove line to start with folds closed).
setlocal foldlevel=20

Heredoc highlightingEdit

Some ini parsers suppport heredoc-style parameter settings, for example:

DefaultText = <<EOT

To correctly handle syntax highlighting with heredoc parameters, create file ~/.vim/after/syntax/dosini.vim (Unix), or $HOME/vimfiles/after/syntax/dosini.vim (Windows), containing lines:

syn match  dosinicomment        "^;.*$\|^#.*$"
syn match  dosinilabel          "^\s\+ ="

" Handle heredoc syntax in the dosini syntax.
" Taken from syntax/perl.ini (:%s/perl/dosini/g).
if exists("dosini_string_as_statement")
  HiLink dosiniStringStartEnd   dosiniStatement
  HiLink dosiniStringStartEnd   dosiniString

HiLink dosiniHereDoc dosiniString

syn region dosiniHereDoc matchgroup=dosiniStringStartEnd start=+<<\z(\I\i*\)+      end=+^\z1$+ contains=@dosiniInterpDQ
syn region dosiniHereDoc matchgroup=dosiniStringStartEnd start=+<<\s*"\z(.\{-}\)"+ end=+^\z1$+ contains=@dosiniInterpDQ
syn region dosiniHereDoc matchgroup=dosiniStringStartEnd start=+<<\s*'\z(.\{-}\)'+ end=+^\z1$+ contains=@dosiniInterpSQ
syn region dosiniHereDoc matchgroup=dosiniStringStartEnd start=+<<\s*""+           end=+^$+    contains=@dosiniInterpDQ,dosiniNotEmptyLine
syn region dosiniHereDoc matchgroup=dosiniStringStartEnd start=+<<\s*''+           end=+^$+    contains=@dosiniInterpSQ,dosiniNotEmptyLine



Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki