Vim Tips Wiki
No edit summary
(Undo revision 35287 by 109.251.103.14 (talk) Not helpful to replace tip with a script. Where did it come from?)
Line 1: Line 1:
  +
{{review}}
" Vim syntax file
 
  +
{{TipImported
" Language: Xdebug trace files (context or unified)
 
  +
|id=583
" Maintainer: Derick Rethans <derick@xdebug.org>
 
  +
|previous=582
" Last Change: 2010 Jun 06
 
  +
|next=584
  +
|created=2003
  +
|complexity=intermediate
  +
|author=Tobi
 
|version=6.0
  +
|rating=548/162
  +
|category1=XML
  +
|category2=
  +
}}
  +
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==
" For version 5.x: Clear all syntax items
 
  +
There's a very helpful script at {{script|id=301|text=xmledit}}, but remember to add "syntax on" to your .vimrc.
" For version 6.x: Quit when a syntax file was already loaded
 
if version < 600
 
syntax clear
 
elseif exists("b:current_syntax")
 
finish
 
endif
 
   
  +
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.
syn match begin "^TRACE START"
 
syn match end "^TRACE END"
 
syn match date "\[.*\]"
 
   
  +
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.
syn match min_memory "+\d\+"
 
syn match pls_memory "-\d\+"
 
syn match nll_memory "+0"
 
   
  +
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:
syn match level "->"
 
  +
* Open up "My Computer"
syn match lineno ":\d\+$"
 
  +
* 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 ...
syn match result ">=>.\+"
 
syn match assignment "=> \$[a-z]\+\(->[a-z]\+\)*\ .*="
 
syn match assignment "=> \$[a-z]\+\['\([a-z]\+\)*'\]\ .*="
 
   
  +
----
syn match methodcall "\k\+->"
 
  +
If you want to just check the wellformedness of the xml document then from the vi editor you can use
syn match staticcall "\k\+::"
 
syn match functionb "\k\+("
 
syn match functione ") "
 
   
  +
!xmllint --noout %
syn match main "{main}()"
 
syn match include "include\(_once\)\=('.\+')"
 
   
  +
for more on this command just give
" Define the default highlighting.
 
" For version 5.7 and earlier: only when not done already
 
" For version 5.8 and later: only when an item doesn't have highlighting yet
 
if version >= 508 || !exists("did_diff_syntax_inits")
 
if version < 508
 
let did_diff_syntax_inits = 1
 
command -nargs=+ HiLink hi link <args>
 
else
 
command -nargs=+ HiLink hi def link <args>
 
endif
 
   
  +
:!xmllint
HiLink begin Label
 
HiLink end Label
 
HiLink date Label
 
HiLink assignment Label
 
   
  +
on opening an xml file using vi or vim editors
HiLink level SpecialChar
 
HiLink result Constant
 
   
  +
----
HiLink min_memory Constant
 
  +
To set up syntax folding automatically for XML files put the following lines in your .vimrc
HiLink pls_memory Structure
 
  +
let g:xml_syntax_folding=1
HiLink nll_memory Comment
 
  +
au FileType xml setlocal foldmethod=syntax
 
  +
Hint: If no folds are found, make sure syntax highlighting is on.
HiLink main Structure
 
  +
----
HiLink include Structure
 
 
HiLink lineno Delimiter
 
HiLink methodcall Function
 
HiLink staticcall Function
 
HiLink functionb Function
 
HiLink functione Function
 
 
delcommand HiLink
 
endif
 
 
let b:current_syntax = "xt"
 
 
:set foldmethod=expr
 
:set foldexpr=strlen(substitute(substitute(substitute(substitute(getline(v:lnum),'^TR.*$','',''),'\\s>=>','->',\"g\"),'^\\s.\\{20\\}\\(\\s\\+\\)\\?->.*$','\\1',''),'\\s\\s','\ ',\"g\"))-2
 
:set foldlevel=9999
 
 
" vim: ts=8 sw=2
 

Revision as of 11:00, 14 October 2012

Tip 583 Printable Monobook Previous Next

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.