The other existing answers are all dependent on vim's definition and detection of a block. My strategy for this kind of deletions is to use the c
command combined with with the f
motion and the actual character to stop at. This will then actually delete the stop character, but since it also was the last key you pressed repeating it twice has next to zero cost, and that will insert it again since c
changes to insert mode.
To explain with examples, for
func1(x|, func2(), y);
the command c2f))
will give
func1(x)|;
which might at first seem less elegant than some of the other answers, however notice that this strategy is universal and does not depend on any block definition.
For instance with
<div| class="some-class">text</div>
the command cf>>
will give
<div>|text</div>
Or when editing csv files like
2016-11-29,question,vi|.stackexchange.com,10435
the command cf,,
will give
2016-11-29,question,vi,|10435
Often I use this to delete the rest of a string, from
printf("Hello world| - a boring example\n");
to
printf("Hello world\|n");
with cf\\
or from
print("Hello world| - a boring example");
to
print("Hello world"|);
with cf""
.
This does change the current position to a slightly different place than asked for, and also changes into insert mode. But I wanted to share my go-to-solution for deleting the rest of anything.
C);
in this particular case.%
motion can do what you're looking for (i.e.d%
).