10.4: Edit binary (and normal) plist files with vim

Aug 10, '05 09:34:00AM

Contributed by: moritzh

Tiger only hintIf you are like me and hate to use Apple's Property List Editor program with its limited capabilites to edit plist files (no searching, always starting with a view with all contents hidden etc.) and prefer to use vim instead for text editing, this one is for you. Using this vim script I created, you can use vim to automatically handle the plist files stored in binary format (new in 10.4). Place the script at the bottom in your .vimrc file. Note that this hint is obviously inspired by some other hints on the same topic but when using emacs.

What does it do? It reads a plist file, checks and memorizes if it is binary, converts it to plain text if necessary and turns on syntax highlinghting for XML. When you save the file again, it is converted to binary again for writing if it was binary in the beginning. If the file was not binary or if the conversion to binary fails (which can happen if you have syntax errors in your file), the file is stored in text format. If an originally-binary plist is saved as plain text due to syntax errors and you fix the errors and save the file again, it is written in binary format. If you open a binary file and just view it without making any changes, you can still exit from vim using the normal :q (no need for :q!) and the file is left untouched (still in binary format). All this should work even when working with several buffers (files), when reading a file into an existing buffer, or when only writing parts of a buffer to file.

Some things to note:

Any suggestions for improvements are welcome, this is the first time I do anything other than simple changes to my .vimrc file.

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050803111126899