Vim Tips Wiki
Register
Advertisement
  1. <?xml version="1.0" ?>
  2. <cross-domain-policy>
  3. <allow-access-from domain="*" />
  4. </cross-domain-policy>

created 2003 · complexity intermediate · author Tobi · version 6.0


If Vim is your main text editor, and if you do a lot of XML editing, then this mini how-to might help you make that even more fun: Vim as XML Editor.

Comments[]

There's a very helpful script at xmledit, but remember to add "syntax on" to your .vimrc.

Overall, the above tutorial is good. I'd probably give it a 9 out of 10. For users that are already familiar with Linux style commands the tutorial is extremely good.

I know that you say you abhor associating file extensions with content-types (which makes sense given your background). However, in a Windows environment I find it very convenient to use file extensions and most Windows users are probably used to this idea anyways... .doc files are Word, .xls is Excel, etc.

Since you know the command line argument it isn't too hard to create the file associations. To set up (for example) an association for xmlstar on Windows 2000 you do the following:

  • Open up "My Computer"
  • Go to Tools -> Folder Options -> (tab) File Types
  • Find XML in the list (you can substitute any extension here)
  • Under "Details" in the box below see if "Advanced" is an option. If it is not, then write down what the current program name is and hit "Restore"
  • Under "Details" choose "Advanced"
  • Select the "New" button
  • In the "Action" box this is what shows up in the context menu. A good name here is XMLSTAR.
  • In the "Application used to perform this action" box you type the following:
cmd.exe /k "C:\path\to\xmlstar\xml.exe -flags_go_here %1" but you replace the flags_go_here with whatever flags you want.

Note: The variable %1 in the file types menu is going to be the name of the XML file and AFAIK you can't pass any other command line options this way. But, this gives you a quick and easy way to open up a file with XMLSTAR. You can of course modify what I've said above to enable VIM for .txt files, or xmllint for XML files, or ...


If you want to just check the wellformedness of the xml document then from the vi editor you can use

!xmllint --noout %

for more on this command just give

:!xmllint

on opening an xml file using vi or vim editors


To set up syntax folding automatically for XML files put the following lines in your .vimrc

let g:xml_syntax_folding=1
au FileType xml setlocal foldmethod=syntax

Hint: If no folds are found, make sure syntax highlighting is on.


script at xmledit, but remember to add "syntax on" to your .viabhor associating file extensions with content-types (which makes sense given your background). However, in a Windows environment I find it very convenient to use file extensions and most Windows users are probably used to this idea anyways... .doc files are Word, .xls is Excel, etc.

Advertisement