vim은 정말 기본적인 수준으로만 사용할 줄 아는데 쓰면 쓸수록 편하게 작업할 수 있는 기능이 많은 것 같다.
한번에 여러개의 config파일을 수정해야했는데 단순하게 몇 개의 라인을 주석처리하고 한두개 문구 추가하는 작업이었다.
예제는 chrony.conf의 일부이다
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
...
먼저 라인 넘버를 확인하기 위해 :set nu를 해준다.
1 # Use public servers from the pool.ntp.org project.
2 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
3 server 0.centos.pool.ntp.org iburst
4 server 1.centos.pool.ntp.org iburst
5 server 2.centos.pool.ntp.org iburst
6 server 3.centos.pool.ntp.org iburst
7
8
...
이제 3번부터 6번라인 앞에 # 하나만 붙이면 되는데 한번에 입력하려고 한다.
:3,6s/^/#/g
3~6번 라인 맨 앞에 주석이 달렸다.
1 # Use public servers from the pool.ntp.org project.
2 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
3 #server 0.centos.pool.ntp.org iburst
4 #server 1.centos.pool.ntp.org iburst
5 #server 2.centos.pool.ntp.org iburst
6 #server 3.centos.pool.ntp.org iburst
7
8
...
참고: 하이라이트로 표현되는게 신경쓰이면 :nohl을 입력해준다
그런데 만약 이런식으로 여러 라인에 주석을 달아뒀다가 지우려면 어떻게 해야할까?
입력할 줄은 알았는데 삭제할 줄을 몰라서 조금 버벅거렸다..;
:3,6s/^.//g
3~6번라인을 수정(s)할건데 맨 앞에서부터(^) 한개의 문자(.)를 삭제(//, //사이에 다른걸 넣으면 해당 문자로 변경)한다는 뜻이다.
이제 조금 더 편하게 작업을 할 수 있을 것 같다 ㅎㅎ