powernest
powernest

Reputation: 251

Delete backwards from end of the line character

I know this sounds very easy, but I couldn't find an elegant way to do it.

I have to retain the below line but remove */ from the end:

(This line is needed);*/

I pressed g_ to move to the last character (i.e. /). Now how do I delete only the */ to get

(This line is needed);

I tried dT* and db — neither works as expected.

Upvotes: 1

Views: 187

Answers (2)

jamessan
jamessan

Reputation: 42667

Backwards motions (like b) are exclusive, which is why the character under the cursor isn't getting deleted. The canonical way to change the backwards delete to be inclusive is to use visual mode, e.g. dvb or dvF*.

Note that neither dT* nor dvT* will do what you want since that's is a till motion, which moves up till, but not including, the specified character. f/F are the corresponding motions which include the character.

Upvotes: 2

Kent
Kent

Reputation: 195049

is this ok?

$xx

$ - to the end of line
xx - remove the last two chars

or if you have many other chars after last *:

$F*D

or use :s command if you have many lines to handle.

Upvotes: 2

Related Questions