I have multiple lines with the key "booktitle":

  booktitle={Advances in Cryptology - CRYPTO' 89 Proceedings},
  series={Lecture Notes in Computer Science},

I would like to replace the uppercase letters of each value with {LETTER}, i.e.

  booktitle={{A}dvances in {C}ryptology - {CRYPTO}' 89 {P}roceedings},
  series={Lecture Notes in Computer Science},

Could you help me please?


To obtain this result you could use :substitute, for example with the cursor on the first line:

  • \u\+ one or more uppercase character: equivalent to [A-Z]\+, see:h \u
  • \0 whole matched pattern, see :h sub-replace-special
  • g is a flag needed to replace all occurrences in the line unless gdefault is on

To affect more than one line, you can specify a range, e.g. :%s for the entire file.

In order to execute this substitution multiple times but only on lines starting with a defined pattern (/^ booktitle=/ in this case), :global is probably what you want:

:g/^  booktitle=/s/\u\+/{\0}/g
  • I just have a try, It works well, Thanks for your answer. Apr 29 '18 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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