![vim에서 패턴을 찾고 바꾸는 방법](https://linux55.com/image/133989/vim%EC%97%90%EC%84%9C%20%ED%8C%A8%ED%84%B4%EC%9D%84%20%EC%B0%BE%EA%B3%A0%20%EB%B0%94%EA%BE%B8%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
현재 전망;
P12104001;example_01_01,
P12104002;example_02_01,
P12104003;example_03_01,
P12104004;example_04_01,
있었으면 좋겠다.
<example_01_01>,
<example_02_01>,
<example_03_01>,
<example_04_01>,
gvim에서 바꾸기를 사용하는 옵션을 제안해주세요(표시된 영역의 문자열만 바꿀 수 있도록. 예는 아래에 있음 :'a,'b s \*******\<******>
)
답변1
~부터 시작하다
P12104001;example_01_01,
P12104002;example_02_01,
P12104003;example_03_01,
P12104004;example_04_01,
이와 관련하여
P12104001;example_01_01,
<example_02_01>,
<example_03_01>,
P12104004;example_04_01,
사용
:/002/,/003/s/.*\(example_.._..\)/<\1>/
읽다
: Command
/Start of section/,/End of section/
s/ substitute
.* all chars up to
\(string to remember . for wild chars\)
/< with
\1 put in the remember string
>/ rest of replacement.
줄 범위를 지정하는 다른 방법을 보려면 Vim에서 :help address를 사용하세요.
답변2
Fred Gannett은 이미 귀하의 질문에 답변했지만 귀하의 의견에 답변하려면 다음을 수행하십시오.
%s/.*\(example_\d\+_\d\+\).*/<\1>,/
"예제" 뒤의 숫자를 하드코딩하지 않고 전체 파일을 대체합니다. 범위를 제한하려면 시각적 선택 또는 이와 유사한 것 .,3s/.*\(example_\d\+_\d\+\).*/<\1>,/
(현재 행에서 세 번째 행까지)을 사용하십시오.
정규식을 포함하는 모든 줄을 바꿔야 하는지 확인해야 합니다.