I have some text with two dashes:

This is some text -- with two dashes.

I want to delete the space before and after the dashes:

This is some text--with two dashes.

Is there a way this can be done without simply pressing x on each space?

I thought maybe vim-surround works with spaces, so I tried ds<Space>, but it didn't work.

  • 1
    There's not really an idiomatic shortcut for this. You could make a mapping or something, or custom operator for this, but I doubt it would end up much shorter than XElx or Xf x
    – DJMcMayhem
    Apr 9, 2019 at 21:21

2 Answers 2


I'd go for a substitution:

:%s/ \+-- \+/--/gc

With g flag to be executed globally on the lines (not only first occurrence per line) and c to confirm (to make sure it does not change things you did not want)


vim-surround by tpope on github

I have tried following undocumented feature of vim-surround


and it worked for me.

This has been added in commit Support ds<space><space> (7 Aug 2015 ). This commit was added after the release of version 2.1 (2015-02-08) which is currently the newest version on vim.org. Therefore, this feature is only available if you have pulled in a newer version from github. Most plugin manager, e.g. vim-plug or minpac, do this anyway.

BTW, there is an alternative plugin vim-sandwich which supports this as well (here by default sd<space>).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.