Vim Tips Wiki
(removed cat. LangSpec, to conform to other pages.)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
[[Category:XML]]
 
 
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=583
 
|id=583
  +
|previous=582
|title=Vim as XML Editor
 
  +
|next=584
|created=October 10, 2003 4:14
+
|created=October 10, 2003
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Tobi
 
|author=Tobi
 
|version=6.0
 
|version=6.0
 
|rating=548/162
 
|rating=548/162
|text=
 
If Vim is your main text editor, and if you do a lot of XML editing, then this mini howto might help you to make that even more fun:
 
 
[http://www.pinkjuice.com/howto/vimxml Vim as XML Editor]
 
 
}}
 
}}
 
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: [http://www.pinkjuice.com/howto/vimxml Vim as XML Editor].
   
== Comments ==
+
==Comments==
 
Overall, the 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 appreciate any feedback. Error reports are especially welcome.
 
email: tobiasreif pinkjuice com
 
   
 
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.
Tobi
 
   
 
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"
tobiasreif pinkjuice com
 
 
* Go to Tools -> Folder Options -> (tab) File Types
, October 13, 2003 3:41
 
 
* 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"
Tobias,
 
 
* Under "Details" choose "Advanced"
 
 
* Select the "New" button
This is a most excellent tutorial! Many thanks for your work in putting this documentation together. I hope that others find it as useful.
 
 
* 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:
Do you have any info about using Vim to edit DocBook files? It'd be nice to have folding support. Is this possible?
 
 
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.
 
Thanks,
 
William
 
 
william at knowmad dot com
 
, December 29, 2003 14:15
 
----
 
Hi William,
 
 
thank you very much for the kind words.
 
 
''> Do you have any info about using Vim to edit DocBook files? ''
 
 
Various sections use DocBook as example language , see
 
* http://www.pinkjuice.com/howto/vimxml/tasks.xml
 
and
 
* http://www.pinkjuice.com/howto/vimxml/moretasks.xml
 
I recommend to set up OASIS catalogs, see
 
* http://www.pinkjuice.com/howto/vimxml/setup.xml#catalogs
 
 
If you have more specific questions feel free to post them here or to send them via email.
 
 
''> It'd be nice to have folding support. Is this possible?''
 
 
Yes, folding is discussed shortly in
 
* http://www.pinkjuice.com/howto/vimxml/tasks.xml#creatingdocuments
 
See
 
* http://www.pinkjuice.com/howto/vimxml/setup.xml#vimrc
 
under <tt>map &lt;Leader&gt;x </tt>
 
for stuff to set:
 
:set filetype=xml&lt;CR&gt;
 
\:source $VIMRUNTIME/syntax/xml.vim&lt;CR&gt;
 
\:set foldmethod=syntax&lt;CR&gt;
 
[...]
 
 
Tobi
 
 
tobiasreif pinkjuice com
 
, December 31, 2003 8:54
 
----
 
Can Vim suggest valid tags based on context?
 
 
Thx for the tutorial
 
 
ancechu2003--AT--terra.es
 
, November 19, 2004 0:15
 
----
 
http://www.pinkjuice.com/howto/vimxml/intro.xml
 
 
"Vim is a text editor, and even when extended with some XML specific functionality, it is not a full-blown XML editor: For example, there's no tags- or WYSIWYG view, and no real structure/tree view. I don't really miss entry help (context-sensitive suggestions for completion), but this and other schema-driven (DTD, WXS, RNG, etc) functionality found in editors like nXML could be implemented using Vim's Python interface plus libxml's Python bindings, for example."
 
 
 
tobi
 
, March 12, 2005 3:10
 
----
 
Overall, the 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 -&gt; Folder Options -&gt; (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 ...
 
'''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 ...
   
jason dot barnett [at] telesuite dot com
 
, March 15, 2005 9:26
 
 
----
 
----
 
If you want to just check the wellformedness of the xml document then from the vi editor you can use
Hi,
 
   
 
!xmllint --noout %
If u want to just check the wellformedness of the xml document then from the vi editor u can use
 
   
 
for more on this command just give
!xmllint --noout %
 
   
 
:!xmllint
for more on this command just give
 
   
 
on opening an xml file using vi or vim editors
:!xmllint
 
   
on opening an xml file using vi or vim editors
 
 
ajaymsrivatsav--AT--rediffmail.com
 
, March 29, 2005 22:50
 
 
----
 
----
I'm having trouble using folding with the XML syntax file distributed in 6.3.n.
+
I'm having trouble using folding with the XML syntax file distributed in 6.3.n.
   
 
It says to use:
 
It says to use:
   
let g:xml_syntax_folding = 1
+
let g:xml_syntax_folding = 1
   
but that doesn't seem to work for me (no fold found).
+
but that doesn't seem to work for me (no fold found).
   
The workaround - which is still pretty good - is to keep your XML in shape with xmllint. Not sure it would work well with CDATA, though.
+
The workaround - which is still pretty good - is to keep your XML in shape with xmllint. Not sure it would work well with CDATA, though.
   
sseye--AT--ahab.com
 
, April 22, 2005 13:35
 
 
----
 
----
 
[[Category:XML]]
A few days ago I had syntax folding working and I got really used to editing XML files with folding enabled.
 
 
Then I must have changed something in my .vimrc, and now I can't get syntax folding to work :(. (indent folding still works, but not what i need). This is in 6.3.46 and 6.4 (different machines, same results)
 
 
The following properties are set - I just can't wrap my head around why this wouldn't work:
 
 
filetype=xml
 
syntax=xml
 
foldmethod=syntax
 
 
 
here's my vimrc:
 
set tabstop=4
 
set shiftwidth=4
 
set vb
 
set autoindent
 
set cindent
 
syn on
 
set incsearch
 
set hlsearch
 
set confirm
 
set foldmethod=syntax
 
set history=100
 
set path+=/home/me/**
 
set suffixesadd+=.java
 
set isfname-=.
 
colorscheme torte
 
 
Any help would be greatly appreciated.
 
 
paulivanov--AT--yahoo.com
 
, May 16, 2006 16:23
 
----
 
I can't get the vim.xml in $ADDED loaded, I have to put it in my ~/.vim/plugin which force me to have it loaded automatically, each time I open .xml file. There is no error, it is just that nothing from within this file is taken into account in my buffer (e.g., after typing ',x', I get "XML mode is on" but no completion of tags). I like the approach to be independent from the extension : could you help me get it working ?
 
 
khub--AT--ifrance.com
 
, May 17, 2006 14:01
 
----
 
Well done.
 
I'm working on openoffice xml files which are ugly oneliner.
 
Your tutorial saved hours of my time (:%!xmllint --format -)
 
THX!!!
 
 
'''Anonymous'''
 
, August 3, 2006 7:21
 
----
 
<!-- parsed by vimtips.py in 0.555995 seconds-->
 

Revision as of 07:32, 4 November 2007

Tip 583 Printable Monobook Previous Next

created October 10, 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

Overall, the 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


I'm having trouble using folding with the XML syntax file distributed in 6.3.n.

It says to use:

let g:xml_syntax_folding = 1

but that doesn't seem to work for me (no fold found).

The workaround - which is still pretty good - is to keep your XML in shape with xmllint. Not sure it would work well with CDATA, though.