Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Assuming a line such as:

grep -ir "$@" * | grep -v "/.svn/" | grep -v "/inc/help/" | head -n 100

If the cursor is at the first | and I want to delete until head, how could I do that with t? I know that I could v/hea to select until hea but when I then delete the text I will have removed the leading h in head as well. I could just h back a character, but this is now a chain of workarounds. It works, but I would like to know if there is a better way.

Is there any way to have t depend on two or more characters instead of a single character?

share|improve this question
add comment

5 Answers

up vote 1 down vote accepted

Try this:

:vnoremap / //b-1<left><left><left><left>

When you type v to visually select a region, then type / to begin the search for the end of the region, Vim will enter

//b-1

into the command line with the cursor over the second /. Then you type the 2 or more characters that you wish to terminate the region with and hit Enter. The b-1 tells Vim to search for that pattern and put the cursor one character before (-1) the beginning of the match. See

:help search-offset

You don't have to map /. You could map t or some other character instead.

share|improve this answer
    
Thank you, this is a nice workaround. –  dotancohen Jul 1 '12 at 9:43
add comment

I appreciate all the great answers, and I've learned a bit from them. However, each one required me to count or calculate the offending characters. Even my own question does require me to already know that there exist offending characters!

Thus, the best solution that I have found is to simply dth and if that doesn't delete up to the character that I need, then I can just press . to do it again.

Thank you!

share|improve this answer
add comment

No, t accepts only one character. I'd do vththd.

share|improve this answer
    
But it does accept a count. e.g. d2t| –  Heptite Jun 28 '12 at 17:59
add comment

if you can do it interactively you may try it with easymotion-plugin:

d;;fh -> will grey out all text and mark all h letters red but substitute them by a,b,c,… and then you may hit b to delete to the second h.

I know this description is a bit cryptic - have a look at a youtube-video

Ps.: I forgot to mention ; is my leader key

share|improve this answer
add comment

d2fh will do it in your example.

share|improve this answer
    
Thank you Colin, but that would require me to count how many offending characters are between me and my goal! I'm looking for a general, simple solution. –  dotancohen Jun 28 '12 at 16:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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