I have this string:

private | public-read | public-read-write | authenticated-read | aws-exec-read | bucket-owner-read | bucket-owner-full-control

I would like to find a mnemonic or easy pattern that could allow me to achieve this:

"private" , "public-read", "public-read-write", "authenticated-read", "aws-exec-read", "bucket-owner-read","bucket-owner-full-control"

If am trying first with \w:


But problem is that ignore the colon and returns:


instead of:


Any ideas, tips?

  • 1
    Possible options: [^ |] (anything not a bar or space); \k if - is in iskeyword; \f might work if space isn’t in isfname, though both this and the former may or may not grab the bars (I’m mot sure);
    – D. Ben Knoble
    Mar 27, 2022 at 13:10

1 Answer 1


You can break this up into 3 substitutions and apply them in sequence:

:s/ | /", "/g | s/^/"/ | s/$/"/
  • s/ | /", "/g replaces all the | delimiters with the quote and commas.
  • | s/^/"/ a second substitution places a quote at the start of the line.
  • | s/$/"/ a third substitution places a quote at the end of the line.

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.