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.

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.

share|improve this question
    
For text on just a single line? –  iglvzx Mar 28 '12 at 20:02
1  
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. –  RedGrittyBrick 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

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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.