Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete, including the current character?

Tags:

vim

Let's say I've typed "abcdefg", with the cursor at the end. I want to delete back to the c, so that I only have "abc" left.

Is there a command like d that includes the current character? I know I could do dTcx, but the x feels like a work-around and I suppose there's a better solution.

like image 250
Andreas Avatar asked Apr 04 '13 06:04

Andreas


People also ask

How do I delete my next character?

Pressing the <Backspace> key once deletes the character just before the cursor and moves the cursor backward one space. Pressing the <Delete> key once deletes the character under the cursor.

How do you delete a character in vi?

To delete one character, position the cursor over the character to be deleted and type x . The x command also deletes the space the character occupied—when a letter is removed from the middle of a word, the remaining letters will close up, leaving no gap. You can also delete blank spaces in a line with the x command.

What is the key used in vi editor to delete the entire current line?

Deleting a single line in Vim editor: To delete a line, follow the steps below: First, bring your cursor to the line you want to delete. Press the “Esc” key to change the mode. Now type, “:d”, and press “Enter” to delete the line or quickly press “dd”.


2 Answers

No. Backward motions always start on the left of the current character for c, y and d which is somehow logical but also unnerving.

The only "clean" solutions I could think of either imply moving to the char after c first and then do a forward delete:

Tcde

or using visual mode:

vTcd
v3hd

But, given your sample and assuming you are entering normal mode just for that correction, the whole thing sounds extremely wasteful to me.

What about staying in insert mode and simply doing ?

like image 84
romainl Avatar answered Nov 16 '22 00:11

romainl


try this:

TcD

this will leave abc for your example... well if the abcdefg is the last word of the line.

if it is not the last word in that line, you may do:

ldTc

or golfing, do it within 3 key-stroke:

3Xx or l4X
like image 30
Kent Avatar answered Nov 16 '22 01:11

Kent