We’re rewarding the question askers & reputations are being recalculated! Read more.
45

Vim ships with a macro called matchit that does this for you; all you need to do is activate it with runtime macros/matchit.vim in your vimrc. This will enable you to jump from, eg, a <div> to its </div>. Note that your cursor will have to be inside the angle brackets; if you're on the angle brackets, % will jump from one bracket to the other as ...


23

You can jump between tags using visual operators, in example: Place the cursor on the tag. Enter visual mode by pressing v. Select the outer tag block by pressing a+t or i+t for inner tag block. Your cursor should jump forward to the matching closing html/xml tag. To jump backwards from closing tag, press o or O to jump to opposite tag. Now you can either ...


7

This should almost work, it aligns the attributes slightly different than your example, but it's probably "close enough": autocmd FileType xml let g:formatprg_args_expr_xml .= '." --indent-attributes 1"' Which will format it like as: <List id='list' items='{/sss}' mode='{device&gt;/listMode}' noDataText='{i18n&gt;...


3

I've come up with a search and replace function that should work for you: :%s/\(\s*\)<Latitude>\(-\=\d\+\.\d\+\)<\/Latitude>\_.\s*<Longitude>\(-\=\d\+\.\d\+\)<\/Longitude>/\1<Point><coordinates>\3,\2<\/coordinates><\/Point>/ Make sure to save your work as this command is destructive. :%s Does a search and ...


3

Here is a solution which is not perfect but not that bad: First add these lines to your .vimrc: function! ReJoinTags() range set nowrapscan let @/='<\(\k\+\)>\([^<]\|\n\)\{-}<\/\1>' let initialLine = line(".") normal ngnJ if initialLine != line(".") call ReJoinTags() endif endfunction Put your cursor on the ...


3

Think of the macros! Really, the regexps by Tumblr41 and Jair Lopez are freakishly smart, but can you really reproduce that in a different case in acceptable time? Here's how I would do it (cursor on line 1): qq record into buffer q ^ go to beginning of line "byit yank lattitude in buffer b j go to next line "ayit yank longitued in buffer a o new line below ...


3

xmllint supports local schema validation, so with Syntastic + xmllint you can accomplish what you want. Once installing both tools, add the following autocmd to your vimrc, tweaking paths to match where the files actually live: autocmd BufNewFile,BufRead /home/nico/xml/commonly_edited.xml call s:xml_validate() function! s:xml_validate() let g:...


3

I commented out my entire .vimrc file, then added a few indentation related things. Using the process of elimination, I landed on the following line being solely responsible getting my XML indentation to work: filetype plugin indent on However, this only worked when loaded from the .vimrc file. Manually typing it in had no effect for me. According to :h ...


3

The xmledit (http://vimawesome.com/plugin/xmledit) plugin allows to jump between open and close tags using <localleader>% Often <localleader> will be \, so you can jump with \% NOTE: Unlike matchit, you don't have to put your cursor inside the tag. Placing it right on the < or > is perfectly fine for the xmledit plugin. :) NOTE 2: A drawback ...


2

You already have most of the pieces: :199 :!C:\apps\xmllint.exe % --format You can use :. for the current line: :.!C:\apps\xmllint.exe % --format To get rid of the preamble before the XML, you can use 0dt<. Inside a command-line, that's done with :normal!: :execute 'normal! 0dt<' | .!C:\apps\xmllint.exe % --format Now, all that is left is ...


2

The Syntastic plugin currently contains support for xmllint from xmlsoft. If you know of another xml lint checker that verifies schema or dtd then it will be your easiest bet to create a Syntastic plugin for it.


2

You can use Operator-pending mode to define new text objects by having the mapping invoke Visual mode, and then select the text you want to operate on. I'm not entirely sure what semantics you want here; the devil is in the details, as usual. But you could try the following: :onoremap iT :<C-U>normal! vitbowV<CR> And then <iT to unindent ...


2

You are right, vim treats tags differently. The plugin vim-indent-object will help you, you can do <ii with it to chance the indent of all lines inside the same indent block.


2

The PHP filetype loads the HTML filetype; from $VIMRUNTIME/syntax/php.vim (around like 63): runtime! syntax/html.vim unlet b:current_syntax This is because PHP is layered "on top" of HTML, and you can start/stop with the <?php and ?> tags. That plugin of yours ships with a ftplugin/html.vim file which load the ftplugin/xml.vim syntax file. The only ...


2

You could use the following substitution command: :%s%<item[^>]\{-}\zs */>\ze%></item>%g In this case I use % as separator instead of /. That way I need less escaping. To explain the regex: <item[^>]\{-} matches <item followed by any number of characters, that are not >. The \{-} matches 0 or more, but as few as possible. \...


1

DBK already show you how to fix it, so i explain only why your approach doesn't work here. From :h feedkeys() : The function does not wait for processing of keys contained in {string}. To show you that: nnoremap ,t :call <sid>foo()<cr>:echom 2<cr> function! s:foo() echom 1 call feedkeys(":echom 3\<cr>") echom 4 endfunction ...


1

There are two <para> because you apply v:count1 to every tag you render. Try this: function s:DocbkPrintTag(tag) " apply v:count1 to the outside tag put =repeat(s:DocbkRenderTag(a:tag), v:count1) endfunction function s:DocbkRenderTag(tag) ... " render single tag here if !empty(include) for incl_tag in include let incl_result .= ...


1

Simply? normal! '< However, I would highly recommend seeing if there is a way to accomplish what you want via simpler (Ex) commands. If you need to do some work over a range, Ex commands are good at it. For example, visually select the lines (e.g., Vap), then :'<,'>normal! Isome text and :'<,'>normal! Asome text. Then you should be able to ...


1

So after doing some more research I came up with something that is able to do this: :%s/<item \(.*\)\/>/<item \1 >\r\t<something>text<\/something>\r<\/item>


1

Try: :g/lang="EN"/s%^\(.\{-}\)\(<span .\{-}</span>\)%\1\2\2%|s%lang="EN"%lang="FR"% Breakdown: g/lang="EN"/ for all lines that contain lang="EN" s%^\(.\{-}\)\(<span .\{-}</span>\)%\1\2\2% ^\(.\{-}\) match the shortest possible prefix \(<span .\{-}</span>\) match from first <span to first </span> \1\2\2 replace with ...


1

First off, I never knew that you can have a search in the range. Thanks for making me learn something new! Second off, you were really close with :g/<line/,/\/>/join. But I'm pretty sure that the problem is that the second line i.e. <line value="abc" value2="def"/> Is also matched by <line/,/\/> so this line is joined with the next ...


1

Using regular expression snippet it's possible to achieve this. Following snippet works almost ideally: snippet "keystroke([^>]\S+)?" "Adds keystroke" r <keystroke>`!p snip.rv = (match.group(1) or "").replace("<", "&lt;").replace(">", "&gt;")`</keystroke>$0 endsnippet It works after you enter all the key sequences, for example: ...


1

If the XML file only have lines in that format you could try this shorter command: :%s/\v\S{-}([0-9.-]+)\_.{-}([0-9.-]+)\S*/<Point><coordinates>\2,\1<\/coordinates><\/Point> Explanation: \v stands for “Very magic”. It means that in the pattern after it all ASCII characters except 0-9, a-z, A-Z and _ have a special meaning, so it ...


1

The suggested solution didn't work for me. formatprg_args_expr_xml is no longer recognized in the current version (at 713e7c2). I solved the issue by adding these two lines in my .vimrc. let g:formatdef_fmt_custom_xml = '"tidy -xml -q --show-errors 0 --show-warnings 0 --indent-attributes 1"' let g:formatters_xml = ['fmt_custom_xml'] Of course I had to ...


1

Another option would be to install Syntastic. It has support for xml lint testing using xmllint. This will do the checking and report errors and not directly fix the problem with the XML however.


Only top voted, non community-wiki answers of a minimum length are eligible