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.
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