7

Assume the content:

foo fnord bar;" >> /tmp/foo/derp
gnarf foo fnord bar;" >> /tmp/foo/derp

I want to jump to the " and delete to end of line and repeat that over the rest of lines.

Yet when I:

f"d$
j
.

it only deletes from my current cursor position to the end of file.

foo fnord bar;
gnarf foo fno

Yet I would have expected the line to read:

gnarf foo fnord bar;

How can I have vim repeat the jump movement as well on repeat?

  • 6
    Can't you just use a macro? qqf"d$j – fruglemonkey Feb 17 '16 at 12:31
10

From the repeat documentation :

.           Repeat last change, with count replaced with [count].
            Also repeat a yank command, when the 'y' flag is
            included in 'cpoptions'.  Does not repeat a
            command-line command.

So, as expected, you're repeating the last change (d$).

If you want to repeat your movement, use ;:

;           Repeat latest f, t, F or T [count] times. See |cpo-;|

IE:

f"d$
j
;.

You could map a binding to perform ;. at the same time, if you want.

| improve this answer | |
1

Like so:

:%s/".*$/

This will substitute everything from the quote to the end of the line with nothing, hence deleting it.

Note that '%' will apply the operation to the whole file.

Use a range instead of % to change a specific sequence of lines:

:1,17s/".*$/

to change lines 1 thru 17, or:

:.,+3s/".*$/

to change the current line and the following 3.

You should see the selections to be changed being highlighted as you type the regular expression, so you'll know if you got it right or not.

PS Yes, I know this is four years too late, but I'm doing this for my own education. The best way to learn is to teach :)

| improve this answer | |
  • 1
    Welcome to Vi and Vim and thanks for contributing! You might want to preface your answer to indicate it doesn't answer the direct question (how to repeat last action with movement) but offers a different approach to solve the same problem. You might also want to discuss the advantages of this approach over the ;. approach from the accepted answer. – filbranden May 7 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.