Learning Vim: the best way to remove the space between words

I am an experienced Windows developer and I am trying to teach myself how to use Vim. I am good at regular expressions and understand the principles of using Vim. However, I have a specific problem, and although I have a solution, it seems to me that it's better to be better.

I have a file that contains a line similar to the following:

CODE<tab><tab>Lorem ipsum dolor sit amet 

There may be a variable number of <tab> or <space> characters between CODE and Lorem . Assuming the cursor is above β€œC” in CODE in normal mode, I want it to be found, this is the key combination that will produce the next output, and leave the cursor between β€œE” CODE and it is β€œL” Lorem in mode insertion.

 CODELorem ipsum dolor sit amet 

My current solution is to use the following key sequence:

w d ? \ s \ + <return>

This works, but it seems illogical to go past the thing I want to remove before I can remove it. I feel like I have to go to the end of CODE and delete forward. I understand this may just be the Vim idiom I don't know about. I could also completely lose a key piece of Vim knowledge.

What is the best way to achieve my goal?

+6
vim command keyboard-shortcuts
source share
2 answers

e l d w will do it.

  • e - go to the end of the word
  • l - move 1 character to the right
  • dw - remove all spaces

If your cursor is in the middle of some space, d i w will remove the spaces to the left and right of the cursor. (If he is somewhere in the middle of the word, he will delete the word.)

+15
source share

Some alternatives:

 :s/\s\+// e xx elxx eldtL f<tab>xx eldw 
+4
source share

All Articles