0

I want to find and eventually delete all whitespace between all occurrences of an equal sign and the next character. For example, turn

@article{article1,
  author=       {author1},
  journal=      {journal1},
  year=         2022,
}
@article{article2,
  author=       {author2},
  journal=      {journal2},
  year=         2022,
}

into

@article{article1,
  author={author1},
  journal={journal1},
  year=2022,
}
@article{article2,
  author={author2},
  journal={journal2},
  year=2022,
}

I tried to do this in vim with the following regex

:s/=\zs\s\+\ze.//

However, an error message is returned:

E486: Pattern not found: =\zs\s\+\ze.

even though all the desired occurrences are highlighted correctly.

Does someone know, what I am doing wrong?

1
  • You can also do it by :%s/=\s\+/=/g
    – auditory
    Commented Mar 5, 2022 at 12:07

2 Answers 2

2

The main problem is that you do not use a range with :s, which means it will only act on the current line. But you regex is also more complicated than necessary. This should work:

:%s/=\zs\s\+//
2

I want to find and eventually delete all whitespace between all occurrences of an equal sign and the next character.

...

With

:s/=\zs\s\+\ze.//

you do substitute on a current line.

Add range to your substitution, all buffer lines % (check :h :range)

:%s/=\zs\s\+\ze.//

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.