Search code examples
vim

Efficient way to remove multiple spaces between two words in Vim


Say I had the following text

 word1 word2              word3 word4

and the cursor was somewhere between word2 and word3.

Question

  • What's the quickest way to replace the multiple spaces between word2 and word3 with a single space in Vim?

Initial thoughts

  • :s/ */ /g

However, I thought there might be something quicker like diw but for spaces.

It would also be good if the strategy also worked when the cursor was on the w of word3 or the 2 or word2.


Solution

  • ciw and then escape back to normal mode, although it will only work if you're on a space.