Let's say I have the following text and my cursor is on the "d"
I want to delete "Word" so that the text reads "someCamelCase"
What's the fewest number of keystrokes required to achieve this?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
In this specific instance, the best I could come up with is 4, including holding the shift key. There are several possibilities.
xxxx - delete the character under the cursor.
3Xx - delete 3 characters to the left, delete the character under the cursor.
3hdw - Move 3 characters to the left, delete to the end of the word.
3hD - Move 3 characters to the left, delete to the end of the line.
Other tries, with 5 keystrokes, that doesn't use repeated commands or movement counts:
dFWx - delete, moving left to the 'W', then delete the remaining character, since the 'd' does not delete the character under the cursor, when moving left.
FWdw - move left to the 'W', then delete to the end of the word.
1 - I only count them as 5 due to holding the shift key down for consecutive keystrokes.
Press x and hold. Wait until it deletes 4 characters, then release it.
As you said, your cursor is positioned at
d. Thus with
?W you can jump the cursor position to
W and with
dw you can remove
In total this is 4 keys pressed, but this saves time on counting characters needed for something like multiple
x keypresses or
4h. Especially will be useful for targeting the capital letter of camelcase words. For instance , with
public static void PaymentsSubmittedToday string and cursor at
y , we can just do
dw, and the string becomes
public static void Payments with cursor at
Search backwards for the fist W, and delete everything up-to and including it.
d means delete and
FW is a motion command that means move the cursor backwards to the first encountered