0

I want to change :

int i = libfnc1();
float j = libfnc2();
libfnc3();

to

int i = lib::libfnc1();
float j = lib::libfnc2();
lib::libfnc3();

using :s

I want to do somthing like :s/libfnc[0-9]/lib::**MATCHED**/g but I haven't found what to put in place of MATCHED

0

You can use either & or \0 for this:

:%s/libfnc[0-9]/lib::&/g 

See :help sub-replace-special for more details.

An alternative approach is to exclude the libfnc... part from the match, by ending the match with \ze:

:%s/\zelibfnc[0-9]/lib::/g

This will search for the entire expression libfnc[0-9] but will only include the part before the \ze (in this case, nothing) in the replacement.

  • neither work :%s/libfnc[0-9]/lib::&/g just replaces the libfncX by lib::& so I think it's related to my dev environment (vim plugin for visual sutdio code) – startresse May 5 '20 at 14:39
  • If you're talking about VSCodeVim then yes, it looks like that doesn't support this feature. Not sure what to suggest about that, sorry. Maybe try editing in Vim! ;) – Rich May 5 '20 at 14:44

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.