7

I've been a long time fan of the t and f motions to modify text up to or including some character. For more complicated criteria, I've started using / followed by a search string to modify text up to a certain phrase.

For example, if I had:

delete this text, but not this.

on a line I could do 0d/not this to delete everything except not this.. This is usually exactly how I want it to work, but every now and then I'd like the pattern to be included in the edit. So, in my previous example, it would have deleted everything except the period.

Is this possible using a similar construct? I'd prefer it to be without the use of additional plugins, but such answer are also welcome.

  • You can always specify what you want to delete with /. I am sure there are more concise ways to do what you want. What is your use case? – jdhao May 17 at 7:38
7

Right as I was about to post the question, I remembered that you can do a search and leave the cursor at the end of the pattern with /e appended to the end of the pattern. Doing 0d/not this/e will delete the line including "not this".

:help search-offset has more information about this and actually has an example similar to what I was trying to achieve (don't I now feel foolish...).

  • I find using e with the previous pattern like so, //e, to be quite handy. You may also want to take a look at using the gn motion. Especially with visual mode which will also accomplish what you are trying to do. See :h gn and Operating on search matches using gn. – Peter Rincker Sep 23 '15 at 19:00
  • 1
    Hey @Pak I way appreciate your answer. You ought to accept (green checkmark) your own answer (to mark this thread as a solved question)! – Robbie Wxyz Nov 11 '15 at 17:44
  • Thanks for the reminder, @SuperScript. I was planning on accepting it,but I think you have to wait few days (and then I forgot about it). – Pak Nov 11 '15 at 18:44

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.