12

I know that I can delete from the cursor till and including the first occurence of a character x with dfx. This only works on one line. How can I delete from the current cursor position till the first occurence of x when x is not in the same line?

E.g., if the cursor is after the first space in

yada yada yada
yada yada yada x yada yada yada x

and I type dfx the result needs to be:

yada

  • 2
    in your example you seem to want to remove until the last occurence of x – guillem Oct 23 '15 at 4:55
  • @guillem you're right. That was a copy-paste error. Anyhow, I tried to accomplish what I asked on the example with the error, but did not manage to do so. I asked another question: delete from cursor till nth occurence of character x. – Erwin Rooijakkers Oct 23 '15 at 9:05
21

Use / for forward search:

d/x<CR>

and ? for backward search:

d?x<CR>
10

I wanted to comment on romainl's answer, but I don't have enough reputation to do so yet!

Although it needs one more keystroke, I find it useful to do v/x<CR>d to see the portion that is being removed.

  • 1
    That's a valid answer. No need to put it in a comment. We're only talking about one piece of software (with its variations), so you don't necessarily need to get fancy to have a valid answer-worthy answer. – Wildcard Oct 23 '15 at 7:17
  • @ErwinRooijakkers you should select this answer if this is what you'll now use. – Paul Evans Oct 23 '15 at 16:03
  • @PaulEvans I don't agree. Although this answer has more practical value for me, I think that the accepted answer provides a better answer to the question asked (since it does exactly what is requested -- I did not ask to see the text highlighted first). – Erwin Rooijakkers Oct 23 '15 at 19:40

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.