sponsor Vim development Vim logo Vim Book Ad

IniParser : This plugin provides functions to read and write ini files for vimscript.

 script karma  Rating 2/2, Downloaded by 546    Comments, bugs, improvements  Vim wiki

created by
Hong Xu
 
script type
utility
 
description
IniParser provides a function for parsing ini files. The following is a short
example of how to use this function.

Assuming you have an ini file in the current directory, whose name is
"planets.ini" with the following content:
=======================
[Venus]
mass=4.86900e24 kg
radius=6051.8 km
satellites=0

[Earth]
mass=5.9742e24 kg
radius=6378.1 km
satellites=1

[Mars]
radius=3397 km
mass=0.64191e24 kg
satellites=2
=======================

Now we want to know the mass of Mars and the radius of the Earth by vimscript.
First we need to parse the file by calling IniParser#Read:

let ini_result = IniParser#Read('./planets.ini')


Then the following two lines shows the mass of Mars and the radius of the
Earth respectively:

echo ini_result['Mars']['mass']
echo ini_result['Earth']['radius']


Here's a little explanation:
The information of the ini file would be stored in the variable "ini_result".
"ini_result" is a dictionary, whose key names are the group names and whose
values are also dictionaries whose key names are entry names and whose values
are the values of the corresponding keys. If you don't understand it, don't
worry, use the following line to show it:

echo ini_result


Here's the result:

{'Earth': {'mass': '5.9742e24 kg', 'radius': '6378.1 km', 'satellites': '1'}, 'Venus': {'mass': '4.86900e24 kg', 'radius': '6051.8 km', 'satellites': '0'}, 'Mars': {'mass': '0.64191e24 kg', 'radius': '3397 km', 'satellites': '2'}}


If you find any bug, please report it to hong@topbug.net or submit it on
the issue tracker:
https://github.com/xuhdev/vim-IniParser/issues

Repository:
Git on GitHub: https://github.com/xuhdev/vim-IniParser

Follow xuhdev on twitter if you are interested in my development:
http://twitter.com/xuhdev
 
install details
Download the IniParser.zip file and extract it to your vim runtime
directory(~/.vim on linux and $VIM_INSTALLATION_FOLDER\vimfiles on windows),
you'd better then use helptags command to generate the help tag(for example
use ":helptags ~/.vim/doc" on Linux).
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
IniParser.zip 0.2.2 2011-10-16 7.0 Hong Xu Also handle the situation that the right side of '=' is empty.
IniParser.zip 0.2.1 2011-10-12 7.0 Hong Xu Problem is: when whitespace is added before or after the equals sign in an ini file it is added to the property name and value.
Now it is fixed.
IniParser.zip 0..2.1 2011-10-12 7.0 Hong Xu Problem is: when whitespace is added before or after the equals sign in an ini file it is added to the property name and value.
Now it is fixed.
IniParser.zip 0.2 2011-02-18 7.0 Hong Xu Add IniParser#Write function which writes ini file.
IniParser.zip 0.1.1 2011-02-02 7.0 Hong Xu Makes the return value of IniParse#Read more meaningful;
improve the document.
IniParser.zip 0.1 2011-01-31 7.0 Hong Xu Initial upload
ip used for rating: 54.204.215.209

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo