Wikia

Vim Tips Wiki

Changes: Dosini files

Edit

Back to page

m (Dosini folding moved to Dosini files: content is now more than folding)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 3: Line 3:
 
|previous=1513
 
|previous=1513
 
|next=1515
 
|next=1515
|created=August 19, 2007
+
|created=2007
 
|complexity=basic
 
|complexity=basic
 
|author=
 
|author=
Line 11: Line 11:
 
|category2=Syntax
 
|category2=Syntax
 
}}
 
}}
Many programs store configuration information in text files with <tt>.ini</tt> extension ("dosini" file type). An example of a section from an ini file is:
+
Many programs store configuration information in text files with <code>.ini</code> extension ("dosini" file type). An example of a section from an ini file is:
 
<pre>
 
<pre>
 
[Preferences]
 
[Preferences]
Line 19: Line 19:
 
</pre>
 
</pre>
   
Vim includes file <tt>syntax/dosini.vim</tt> for syntax highlighting. This tip shows two enhancements: Folding sections, and correct highlighting when heredoc-style parameters are used.
+
Vim includes file <code>syntax/dosini.vim</code> for syntax highlighting. This tip shows two enhancements: Folding sections, and correct highlighting when heredoc-style parameters are used.
   
 
==Folding sections==
 
==Folding sections==
You can enable folding of dosini sections by placing a script in file <tt>~/.vim/after/syntax/dosini.vim</tt> on Unix-based systems, or in file <tt>$HOME/vimfiles/after/syntax/dosini.vim</tt> on Windows systems.
+
You can enable folding of dosini sections by placing a script in file <code>~/.vim/after/syntax/dosini.vim</code> on Unix-based systems, or in file <code>$HOME/vimfiles/after/syntax/dosini.vim</code> on Windows systems.
   
 
The script should contain:
 
The script should contain:
Line 44: Line 44:
 
</pre>
 
</pre>
   
To correctly handle syntax highlighting with heredoc parameters, create file <tt>~/.vim/after/syntax/dosini.vim</tt> (Unix), or <tt>$HOME/vimfiles/after/syntax/dosini.vim</tt> (Windows), containing lines:
+
To correctly handle syntax highlighting with heredoc parameters, create file <code>~/.vim/after/syntax/dosini.vim</code> (Unix), or <code>$HOME/vimfiles/after/syntax/dosini.vim</code> (Windows), containing lines:
 
<pre>
 
<pre>
 
syn match dosinicomment "^;.*$\|^#.*$"
 
syn match dosinicomment "^;.*$\|^#.*$"

Latest revision as of 06:28, July 13, 2012

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:

[Preferences]
AutoFit=1
ToolTips=0
PromptToSave=1

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:

[Preferences]
DefaultText = <<EOT
multi
line
parameter
setting
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
else
  HiLink dosiniStringStartEnd   dosiniString
endif

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

ReferencesEdit

CommentsEdit

Around Wikia's network

Random Wiki