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.


1 Answer 1


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

  • 1
    \d instead of [0-9]
    – D. Ben Knoble
    Commented May 20, 2021 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
    Commented May 21, 2021 at 11:34
  • Welcome to Vi and Vim!
    – filbranden
    Commented May 22, 2021 at 0:04

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