I'm an experienced developer on the Windows platform and I'm trying to teach myself how to use Vim. I am pretty good with regular expressions and understand the principles of how to use Vim. However, I have a specific problem, and although I have a solution, it feels as though there ought to be a better one.
I have a file which contains a line similar to the following:
CODE<tab><tab>Lorem ipsum dolor sit amet
There could be a variable number of <tab>
or <space>
characters between CODE
and Lorem
. Assuming the cursor is over the 'C' of CODE
in normal mode, what I want to be able to do is find a key combination that will produce the following output, and leave the cursor between the 'E' of CODE
and he 'L' of Lorem
in insert mode.
CODELorem ipsum dolor sit amet
My curent solution is to use the following key sequence:
w d ? \ s \ + <return>
This works, but it feels illogical to go past the thing I want to delete before I can delete it. I feel like I should move to the end of CODE
and delete forwards. I realise this could simply be a Vim idiom that I'm not aware of. I could also be totally missing a key piece of Vim knowledge.
What's the best way to achieve my goal?
eldw will do it.
If your cursor is in the middle of some whitespace, diw will delete whitespace left and right of the cursor. (If it is somewhere in the middle of a word, it will delete the word.)
Some alternatives:
:s/\s\+//
e xx
elxx
eldtL
f<tab>xx
eldw
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With