The plugin emmet provides the mapping <C-y>j
to split or join tags. The help section explains what emmet does when using this mapping:
12. Split/join tag *emmet-split-join-tag* *<C-y>j*
To join block, type '<C-y>j'.
>
<div class="foo">
cursor is here
</div>
<
Type '<C-y>j' in insert mode. Then,
>
<div class="foo" />
<
And type '<C-y>j' in there again.
>
<div class="foo">
</div>
Sometimes you have to modify many tags individually because you have to insert different content between the tags which makes a global substitution not perfect. However, a global substitution could still be the first step.
Following steps achieve the change described in the question:
Modify single tag
/<item
to move to tag <item ... />
<C-y>j
(:h emmet-split-join
)
cit
(:h it
)
something<C-y>;
(:h emmet-expand-word
)
text specific for this line<Esc>
n
jump to next <item
which should be changed
Modify all lines and insert the same text everywhere
In this case I would use the :substitute
command similar to you. However, I want to show that it is also be possible to use the plugin in combination with :global
and :normal
(or with a macro not shown here). I assume that all <item .../>
are placed on separate lines
:g/item/exec "norm f<\<C-y>jcitsomething\<C-y>;text"
Formatting
To format your xml source code, you can consider using tidy
for formatprg
by placing following into ~/.vim/after/ftplugin/xml.vim
:
setlocal formatprg=tidy\ -xml\ -quiet\ --indent\ auto\ --tidy-mark\ no\ --indent-spaces\ 2\ --vertical-space\ yes
Now you can format the whole xml file afterwards with gggqG
.
Furthermore, if you like to combine formatprg=tidy ...
with indentexpr=XmlIndentGet(v:lnum,1)
from $VIMRUNTIME/indent/xml.vim
, have a look at following question Automatically reindent lines filtered through formatprg.