문제

I have a number of lines like this:

pointer->[some Random Number Of Alphabets](),

I want to search for this pattern and append .value() to it exactly after the () so it becomes pointer->[some Random Number Of Alphabets]().value(), but what happens is it overwrites the "," and the space after it which I'm intending to leave unaffected. the command I'm using is this:

%s/\(\<pointer->.*()\), \>/\1.value()/

What am I doing wrong here?

도움이 되었습니까?

해결책

I like to use \ze in these cases

:%s/\<pointer->.*()\ze, /&.value()/
  • \ze marks the end of the match
  • & is equivalent to \0
  • remove the \> as I feel like this is an accident. See :h /\>
  • May want to use an non-greedy qualifier like \{-} instead of *, better yet maybe [^(]*
  • May want to use \zs to the mark start of the match and eliminate the need for &. See @Pak's comment below

For more help see:

:h /\ze
:h s/\&
:h /\>
:h /\{-

다른 팁

This should work:

:%s/\v(pointer.*\(\))/\1.value()/
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top