In my text editor, I would like to define a keyboard shortcut (say, CTRL-D) with "delete until character is found" functionality. For example, if the cursor is placed before the "H" of this text:

Here comes the colon:Did you see it?

and you press CTRL-D followed by :, then the text should change to

Did you see it?

just as if you had pressed the Delete button 21 times. (Note that the colon is deleted as well.)

If the character isn't found in the edited text (for instance, if you type CTRL-D followed by x in the above example) I would prefer that nothing happens, but this is not very important. My current text editor is Notepad++, but feel free to suggest solutions involving other editors.

  • For text on just a single line?
    – iglvzx
    Mar 28 '12 at 20:02
  • 2
    If you were using vim, it would be dt: (Delete To colon) or df: (Delete until Find colon). The latter deletes the colon, the former doesn't. However, you aren't using vim, so this is just a passing comment, not an answer. Mar 28 '12 at 20:55
  • @iglvzx I was having "for a single line" in mind, but "for entire remaining text" is also good enough.
    – user12816
    Apr 1 '12 at 11:39

If you are willing to learn a new editor - and by "learn a new editor" I mean kicking and screaming and pulling your hair out for a little while - then the editor Vim/gvim does this sort of thing easily. It's free, available on any OS you can think of, and very bug-free.

Some people never get over the learning curve hump, which is steep but not impossible if you want to learn a very powerful editor. It includes a tutorial built into the editor, and it has both a graphical version (gvim) and a terminal version (Vim).

For your example, you would enter "df:", but if you needed to do it multiple times, you simply press the period for subsequent times. In Vim, "f:" is a "motion command", and simply moves the cursor to the colon; d is a command that deletes whatever motion command follows. Additionally, it can take a count, such as "2df:" to delete the next two colons and all text up to that point.

If you are interested, try the tutorial by running the program, and typing ":help tutorial". This will show some of the power of vim quickly and simply, while allowing you to actually try it out, as the tutorial is shown in the actual editor.

It takes patience and a desire to learn, but it pays off and I personally think it's fun to use.

  • no need to use vim. A simple regex in notepad++ or sed will work
    – phuclv
    May 3 '17 at 4:53

As in the picture shown, replacing would do what you want.

enter image description here

after that you can save replacing as a macro. Then set a shortcut to this macro .

I think the recording a macro don't need to explain.

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.