Delete until character is found

2

1

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.

user12816

Posted 2012-03-28T18:32:08.530

Reputation: 881

For text on just a single line? – iglvzx – 2012-03-28T20:02:26.460

2If 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 – 2012-03-28T20:55:12.507

@iglvzx I was having "for a single line" in mind, but "for entire remaining text" is also good enough. – user12816 – 2012-04-01T11:39:43.603

Answers

1

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.

Marty Fried

Posted 2012-03-28T18:32:08.530

Reputation: 716

no need to use vim. A simple regex in notepad++ or sed will work – phuclv – 2017-05-03T04:53:02.357

2

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.

hamed

Posted 2012-03-28T18:32:08.530

Reputation: 4 960