Home > vim > VIM: `t` motion with two or more characters

VIM: `t` motion with two or more characters

June 28Hits:0
Advertisement

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?

Answers

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.

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

d2fh will do it in your example.

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!

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

Tags:vim

Related Articles

  • VIM: `t` motion with two or more charactersJune 28

    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

  • Vim delete motions include under the cursorJune 22

    If you delete backwards in vim, it doesn't delete the character under the cursor. What do you need to do to have it delete, say, back to the last space? --------------Solutions------------- dT<space> to delete back to a space, where I've used <sp

  • In Vim how to delete all words and characters not matching a patternMarch 1

    I have googled this several times over the years and have not found a good solution so I am giving up and asking. I want to be able to delete all words and punctuations that do not match a pattern. So say i have this list R61,1,BWRBW0471,1 R14,1,BWRB

  • vim: delete from cursor position to n characters before end of lineApril 1

    In vim, with dg_ you can delete the actual cursor position to end of line. How can I delete the actual position to end of line minus some number of characters? example: this<cursor> is a ... many words ... line How do I delete from <cursor> po

  • Make vim's {} motions skip over foldsNovember 6

    I love vim's { and } motions, which jump to the next/previous empty line. I've recently been using folding more, and while that's a great feature, it doesn't do what I would expect with respect to the { and } motions. If there is an empty line in the

  • vim Repeatable Motion that Distinguishes Vertical and HorizontalMay 29

    I've been looking for a plugin like repmo that can repeat my previous horizontal movement and previous vertical movement separately, and reverse the direction of the motion. (e.g. 5j could be repeated with <C-j> and <C-l> would give me 5l). Th

  • Vim motion commands in the Vim command-lineOctober 11

    Sometimes in Vim, I'm typing a command and realise that I could really use Vim's motion commands for navigating the command-line: :s/somthing/else/ realise that I misspelled something. Fmae and be done with it. Of course, trying this would just put F

  • Vim not showing garbage charactersJune 17

    I copied the content of an ant build.xml document from an .odt file to Vim editor. There were no garbage characters I could observe, but the build process failed due to incorrect XML tags. I assume this is due to garbage characters which are invisibl

  • How to find special characters in Linux VimJanuary 22

    I want to find special characters in a text file. It is known that the UTF-8 encoded file contains Chinese characters , "-", "^A"(control-A, which is one of special characters), numbers, alphabets, and some other characters. <- This

  • Vim: What is difference between motion mark shotcut `. and `"?February 24

    While reading vim info motion marker says: |`quote| `" go to the position when last editing this file |`.| `. go to the position of the last change in this file Above two shortcuts seem to be same. I tried both on a new file. first is taking me to th

  • What is the difference between "find" and "till" in vim?July 27

    I see I can use t c or Tc to move to the next / previous character c I can also use fc or Fc to move to the next / previous character c Is the only difference between them that tc places the cursor before the character, Tc (going backwards) places th

  • How to distinguish between \r\n and \n in VIMAugust 7

    In VIM I can show all the hidden characters in a file via the command ":set invlist". However, end of line sequences are always displayed as $ whether it is a carriage return/line feed or just a line feed. How do I distinguish between the two ty

  • How to show characters when using the change "c" commandDecember 17

    I know there is a vim setting that allows you to show characters when using the change command, I just can't find what it is. Ex: "This is a<ci"> string" Inside the <> is where I use the ci" command to change the quotes. Th

  • (Mac)VIM disable NerdTREE for new and single filesOctober 23

    I have configured NerdTree to open up when i start VIM by using Pathogen and placing NERDTree in my .vim/bundle directory. I have installed NERDTreeTabs the same way. I don't want NERDTree to open though, when i am either opening a single file or cre

  • Motion is saving images to home directoryNovember 27

    I was interested in setting up a home security network. I installed Motion in Ubuntu 12.04 and it worked fine. Then the next day I went to play around with it some more but the images are not being saved to /tmp/motion as the configuration file state

  • iTerm2 vim cannot map alt keyDecember 10

    I'm having trouble trying to map the alt-key bindings on vim in iTerm2. I want to map shortcuts for switching between buffers like this: map <A-Right> <C-w>l map <A-Left> <C-w>h map <A-Down> <C-w>j map <A-Up> <

  • Uncommenting multiple lines of code, specified by line numbers, using vi or vimJuly 30

    I have learned from this Stack Overflow question that it is possible to use vi/vim to comment out a specified range of line numbers. For example, suppose I have the following bash script: #!/bin/bash This is my very very great script Now suppose that

  • Underline under English word after Japanese in vim

    Underline under English word after Japanese in vimDecember 22

    As you can see in the image, I have an underline under English word after Japanese. Q1. Why there is no underline under Japanese? Q2. How to get rid of it. Q3. Is it because of syntax on? Thanks in advance. --------------Solutions------------- This i

  • What is Sublime Text 2's equivalent to vim's Ctrl+P?February 6

    Sublime Text is great, but Ctrl+P (and Ctrl+N) in vim (inserting a word with same starting characters in insert mode) is such an essential feature that I just cannot live without it. Is this functionality available in Sublime Text 2? --------------So

  • Which default encoding for Vim: utf8 or latin1?July 1

    I'm writing text in European languages as French, German, Italian. All characters are compatible with latin1 encoding. Thats why I decided to set the default encoding in vim to latin1. Once in a while I have problems p.e. the latest ycm plugin doesn'

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.874 s.