Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete till backward in vim

Tags:

vim

I know how to delete until a char forward, like using dtx to delete till the x char from current cursor onwards. But how can I to do that backwards?

Say I have the following:

"abc I want to delete back to I"

And the cursor is at the end of the line, I want it to be "abc ".

like image 721
Daniel Wu Avatar asked Aug 21 '14 06:08

Daniel Wu


2 Answers

In general, capital letters reverse. So we have:

  • t do something until a character
  • T do something BACKWARDS until a character
  • f do something until and including a character
  • F do something BACKWARDS until and including a character
like image 138
BenjaminRH Avatar answered Nov 15 '22 14:11

BenjaminRH


I guess the problem is not how to remove till/to (T/F) the char backwards. You need delete the char under cursor too , in your case, the last I. leaving abc<space> at the end.

option 1: (3 key strokes)

You can move to the first I backwards, than D:

FID

option 2: (4 key strokes)

or move cursor to the beginning, do it forwardly.

0FID

option 3: (4 key strokes)

you can do an extra x.

dFIx

option 4: (4 key strokes)

with v:

vFIx
like image 34
Kent Avatar answered Nov 15 '22 15:11

Kent