I'm editing some large YAML files with neovim, and need to add (and remove, in some cases) single quotes around some values.

For example -

code: 1234

needs to be changed to

code: '1234'

in other cases,

account_number: '1234'

needs to be changed to

account_number: 1234

I've tried :%s in as many ways I can think of, but can't solve it. Any suggestions?

Thank you.


This does it: :%s/"\([0-9]\+\)"/\1/g

  • 1
    \d instead of [0-9]
    – D. Ben Knoble
    May 20 at 19:38
  • 2
    @Steve note that your answer is flagged as low quality because of its length. I would be useful to edit it to add an explanation of your command so that someone who is not familiar with :s and regex can better understand what you are doing.
    – statox
    May 21 at 11:34
  • Welcome to Vi and Vim!
    – filbranden
    May 22 at 0:04

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