Let's say I have the following text and my cursor is on the "d"
someCamelCaseWord
^
I want to delete "Word" so that the text reads "someCamelCase"
What's the fewest number of keystrokes required to achieve this?
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[1], 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.
FWdw
should be FWde
and 3hdw
should be 3hde
. 3hD
assumes a bit to much.
vFWd
or v3hx
and vFWc
if you want go to insert mode.
Commented
Aug 20, 2016 at 17:53
One.
Press x and hold. Wait until it deletes 4 characters, then release it.
ThatIsAVeryLongCamelCaseName
which can happen ? Plus it's kind of like using backspace in other editors.
Commented
Aug 20, 2016 at 9:12
As you said, your cursor is positioned at d
. Thus with ?W
you can jump the cursor position to W
and with cw
or dw
you can remove Word
.
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 ?S
then dw
, and the string becomes public static void Payments
with cursor at s
dFW
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 W
character.
Word
or you have a generic names likesampleVarNameAbc
where you would like to delete last sequence of letter beginning with uppercase (Abc in this case)?x
.gw
. If I want to delete a camel-case sub-word, I just typedigw
(instead ofdiw
, which would delete the entire word). The plugin: github.com/chaoren/vim-wordmotion An alternative plugin: github.com/bkad/CamelCaseMotion