vim - :s/var\zs\d\+/\=(submatch(0)+1)/

ruseel의 이미지

명예의 전당에 있는 "Vi vs Editplus" 글타래에 Santana 님께서

Quote:
var1 => var2
var2 => var3
var3 => var4
var4 => var5
var5 => var6
. .
. .
var999 => var1000

이런 치환을 하고 싶을 때

:s/var\zs\d\+/\=(submatch(0)+1)/

위와 같은 명령을 사용하셨습니다.

여기서 '\z' 가 뭘까요?
(vim 매뉴얼에서 어디를 찾아봐야 할까요?)

jellypo의 이미지

정규표현식에서 찾아보셔야 되고요.
vim help 에서 찾아보실 수 있습니다.
*regular-expression* *regexp* *Pattern*

근데 \z는 뭔지 모르겠군요.;

5. An atom can be one of a long list of items.  Many atoms match one character
   in the text.  It is often an ordinary character or a character class.
   Braces can be used to make a pattern into an atom.  The "\z(\)" construct
   is only for syntax highlighting.

   atom    ::=      ordinary-atom               |/ordinary-atom|
                or  \( pattern \)               |/\(|
                or  \%( pattern \)              |/\%(|
                or  \z( pattern \)              |/\z(|

영어가 짧아서 해석은 ........T_T;

|/\zs| \zs \zs anything, sets start of match 이거 같기도 하네요. ...

제 생각엔 \z가 아니라 \zs 같습니다.
var 뒤에 나오는 패턴이 숫자(digit?)라면 그 숫자에 +1을 한다는거 여기까진 이해하겠는데 \= 사용 이후는 모르겠군요.

ruseel의 이미지

\zs	

Matches at any position, and sets the start of the match there: The next char is the first char of the whole match. |/zero-width| Can be used multiple times, the last one encountered in a matchingbranch is used.	Example: "^\s*\zsif" matches an "if" at the start of a line, ignoring white space.
{not in Vi} {not available when compiled without the +syntax feature}

늘 var1 -> var2로 바꾸는 것 처럼 패턴의 일부분을 바꿀 일이 있다면
\(, \) 을 앞뒤로 치는 수고를 하곤 했는데 이런 좋은 방법이 있었네요. 감사합니다.

\= 뒷부분에 들어갈 수 있는 표현식은 manual에서 eval.txt 안에서 찾았습니다.

help \\zs
help submatch