I understand that vi has shortcut keys to delete characters, words and lines with various options.
However, I could not find this:
- delete from the cursor to the next specified character
For example, I might type du"
expecting the editor to "delete until the next "
character is found"
The closest I know is d9w
where 9
is the number of words to delete.
Does anyone know if this is possible?
Use dtc, where c is any character, e.g. for you, you want dt"
This will delete upto but not including c.
If you had:
And the cursor was at the first space and you typed dt!, you would get:
Also dfc.
This will delete upto and including c.
Using df! on the same example above would give you:
Just about any "motion" can be used for the
d
,c
,y
and similar commands.To delete forward up to character 'X' type dtX
To delete forward through character 'X' type dfX
To delete backward up to character 'X' type dTX
To delete backward through character 'X' type dFX
The input dt# (not a :command, use it like a movement like G)
will delete from the cursor until but not including the #. You can substitute any char for #.
It looks like @Arcege already answered the question, but I did
d/l
to delete until the characterl
; other characters would work as well.w
moves to the following word.l
moves to the following charactor.So it's
d9l
to delete the next 9 characters.I suggest use
delete with pattern
,d/<pattern>
d is action delete
/ is vim searching sign
for example, the following is a MySQL connection string. I want to change to the password
redhat
to new oneroot:redhat@tcp(localhost:3306)/?parseTime=True
In command mode , I click
w
(skip to next word), the cursor move to ":", clickw
again will move the cursor to first charr
of passwordredhat
. now clickd/@
will delete the any characters until@
that in this case will remove theredhat
.d/@tcp
is better if the string has more than one@
, the pattern more paticular is more precise.Nobody mentioned about that so I thought I would share this as well.
If you want to delete until a character you can use
dt
and type the desired character. If you want to delete until a character but the character is also in the middle for instance(hell(o) world)
and you want to delete fromhell(o)
until the last)
and your cursor is on theh
you can type a number, in this case2dt)
this will jump the first)
.You can also use
de
(delete end), here by "end" you have to think "end of the word (not line)" so if you want to delete for instance.world
in(hello.world)
and your cursor is on the dot, you can typede
.Hope it helps