An efficient way to remove spaces between two characters in Vim

I have faced this problem a lot. For example,

abcd abcd

xyzw xyzw

Now I need to remove spaces between single characters. The lines also have some symbols on the front.

I want to try something like this: s / [az] [az] / [az] [az] / g - what might be possible to replace the expression?

This is just an example of a problem. I run into similar problems a lot of the time when I have to apply some search to find this type of expression and replace the expression, but not completely replace it and replace only part of it.

Edit: want to remove one space between single characters.

+3


source to share


2 answers


Use a regular expression with sets of substrings:

s/\([a-z]\) \([a-z]\)/\1\2/g

      



the \ 1 refers to the characters matched by regex between the first \(...\)

and \ 2 characters matched by regex between the second\(...\)

+7


source


Thank. I had a similar problem. I wanted to remove all spaces from all numbers in a row, but keep spaces elsewhere.

%s/\\([0-9]\\) \\([0-9]\\)/\1\2/g

      



did the trick.

+1


source







All Articles