STUDY
Vim - Select Multiple Cursors 본문
Vim - Select Multiple Cursors
Vim에서 Sublime Text의 `Ctrl+d` key와 같은 기능을 사용하는 방법 몇 가지.
1. Regular Expression
Vim에서 regular expression을 써서 선택한 후에 치환하는 방법이다. 찾아 바꾸기. [ Vim Doc: Search Pattern ] 이렇게 하면 문서의 처음부터 찾아 바꾸는 식이기 때문에, 문서 중간부터 일부만 선택하거나 중간에 바꾸지 않을 경우에는 불편하다. 뭔가 방법이 있을 것 같지만, Vim 문서 전체를 정독하고 싶지는 않다.
/ find all
/i all words containing character 'i'
\<i word begins with character 'i'
/<i word ends with 'i'
\<i\> word begins and ends with 'i', word == 'i'
/\<i\> find all words 'i'
:%s/foo/bar/g
Find each occurrence of 'foo' (in all lines), and replace it with 'bar'.
:s/foo/bar/g
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.
:%s/foo/bar/gc
Change each 'foo' to 'bar', but ask for confirmation first.
:%s/\<foo\>/bar/gc
Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.
2. Visual Mode
Normal mode에서 `v` 키를 눌러 visual mode로 바꾼 후에 편집하는 방법
3. Plugin - vim-multiple-cursors
Visual mode로 바꾼 후에 Ctrl+n 을 여러 번 누르면서 선택하고 바꾸는 방법이다. 건너 띄는 키 등 편리한 기능이 많지만, Windows 10에서는 작동이 조금 불안한 것 같다.
4. Plugin - scalpel
Vim의 regex을 응용하되 조금 편리하게 바꾼 plugin이 존재한다. 명령은 대문자로 시작하는 `Scalpel`인데, 그 다음에는 아래와 같은 regex 패턴을 맞추어 Regex before를 Regex after로 치환한다.
:Scalpel /[Regex before]/[Regex after]/
'emacs' 카테고리의 다른 글
Emacs Configuration File (0) | 2020.11.25 |
---|---|
gVim Configuration (0) | 2020.06.04 |
Useful key bindings (0) | 2019.02.06 |
Changing the location of Emacs' config. file (0) | 2019.01.24 |
Comments