I've html file (e.g. curl -o page.html http://example.com/) where I would like to remove inner html block for given html tag.
I've the following code which works:
$ ex -V1 page.html <<-EOF
/<h1>
norm nvitd " Jump to next match and remove the inner tag block.
wq
EOF
However I'd like to make the condition to execute norm nvitd only when the pattern <h1> is found. For example when testing with <h2> then the next line is executed generating the warnings, despite the pattern is not found.
How to make such condition? It's possible to make it in one line (like a ternary operator)?
n, because I'm confused when Vim set the cursor on matched pattern and when it's not. I guess in Ex mode it doesn't set cursor properly on the pattern (it seems so, because the tag is at the beginning of the line), but when it is in the middle, it won't work. So I think thenis necessary to make this works for these both cases. See: this for more details. – kenorb May 16 '15 at 10:44exto make and look it simple as part of the script and I'm learning it at the same time. Secondly it's distributed widely by default (opposite to vim). The other thing is that I can always add silent (-s), so the screen doesn't blink when I run the script and I can also deal with stdin and stdout easily. I know I can useviinstead ofvim, but on OSX it's linked tovimby default, so it's the same thing (so I can't check the compatibility of my changes with plainvi), that's why the easiest way for me is to useex, so it's cross-platform compatible. – kenorb May 16 '15 at 11:06exspecific thing, the same happens in Vim Ex-mode that the cursor isn't set properly, so you've to still usen(when the string is somewhere in the middle of the line). Unless you've some better idea. – kenorb May 16 '15 at 11:19ditwould be simpler (and faster?) for a batch command. – Vitor May 18 '15 at 13:36/{pattern}/[cmd]syntax? Is it:help :/? But then I can't find explanation for[cmd]. – kenorb Oct 25 '15 at 19:46:help :/defines/{pattern}/as a range. Not all Vim commands take such range, but in those that do, it is indicated at the corresponding:help {cmd}page; all Ex commands are listed under:help :index– Ingo Karkat Nov 02 '15 at 14:12