0

I have multiple lines with the key "booktitle":

  booktitle={Advances in Cryptology - CRYPTO' 89 Proceedings},
  volume={435},
  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},
  volume={435},
  series={Lecture Notes in Computer Science},

Could you help me please?

5

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

:s/\u\+/{\0}/g
  • \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
| improve this answer | |
  • I just have a try, It works well, Thanks for your answer. – Wang Shidong 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.