숭고한 텍스트처럼 Vim 멀티 라인 편집?
gvim을 사용하기 시작했고 gvim에서 여러 줄 편집이 어떻게 작동하는지 이해할 수 없습니다.
예를 들면 다음과 같습니다.
원문 :
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
ctrl + q, jjjjjj, $ 모든 것이 선택되면 I 키를 눌러 여러 줄 삽입을 수행합니다.
내 의도는 첫 번째 줄과 같이 따옴표를 삽입하고 Esc 키를 누르는 것입니다.
asd "asd asd" asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
어떻게 된 거예요? 나는 숭고한 텍스트와 비슷한 행동을 기대했습니다.
그것이 어떻게 작동하는지 모르는 경우 모든 라인에 대해 동작을 반복합니다. 어떻게 그렇게 할 수 있습니까? 그리고 vim은 여기서 무엇을하고 있습니까?
Windows 호환성 계층을 삭제하여 호의를 베푸십시오.
Visual-Block 모드로 들어가는 일반적인 단축키는 <C-v>
입니다.
다른 사람들은 매크로 기록을 다루었습니다. 여기 몇 가지 다른 아이디어가 있습니다.
비주얼 블록 모드 만 사용 합니다.
두 번째 단어에 커서를 놓습니다.
asd |a|sd asd asd asd; asd asd asd asd asd; asd asd asd asd asd; asd asd asd asd asd; asd asd asd asd asd; asd asd asd asd asd; asd asd asd asd asd;
히트
<C-v>
입력 시각 블록 모드 및 아래쪽으로 선택을 확장 :asd [a]sd asd asd asd; asd [a]sd asd asd asd; asd [a]sd asd asd asd; asd [a]sd asd asd asd; asd [a]sd asd asd asd; asd [a]sd asd asd asd; asd [a]sd asd asd asd;
I"<Esc>
얻기 위해 명중 :asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd;
세 번째 단어의 마지막 문자에 커서를 놓습니다.
asd "asd as|d| asd asd; asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd; asd "asd asd asd asd;
히트
<C-v>
입력 시각 블록 모드 및 아래쪽으로 선택을 확장 :asd "asd as[d] asd asd; asd "asd as[d] asd asd; asd "asd as[d] asd asd; asd "asd as[d] asd asd; asd "asd as[d] asd asd; asd "asd as[d] asd asd; asd "asd as[d] asd asd;
A"<Esc>
얻기 위해 명중 :asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd;
함께 시각적 블록 모드 Surround.vim .
두 번째 단어에 커서를 놓습니다.
asd |a|sd asd asd asd; asd asd asd asd asd; asd asd asd asd asd; asd asd asd asd asd; asd asd asd asd asd; asd asd asd asd asd; asd asd asd asd asd;
히트
<C-v>
입력 시각 블록 모드 및 하단과 오른쪽으로 선택을 확장 :asd [asd asd] asd asd; asd [asd asd] asd asd; asd [asd asd] asd asd; asd [asd asd] asd asd; asd [asd asd] asd asd; asd [asd asd] asd asd; asd [asd asd] asd asd;
히트
S"
"를 선택을 둘러싸고 :asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd;
함께 시각적 라인 모드 :normal
.
V
전체 줄을 선택하고 아래쪽으로 확장하려면 누르십시오 .[asd asd asd asd asd;] [asd asd asd asd asd;] [asd asd asd asd asd;] [asd asd asd asd asd;] [asd asd asd asd asd;] [asd asd asd asd asd;] [asd asd asd asd asd;]
다음 명령을 실행하십시오
:'<,'>norm ^wi"<C-v><Esc>eea"<CR>
.asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd; asd "asd asd" asd asd;
:norm[al]
allows you to execute normal mode commands on a range of lines (the'<,'>
part is added automatically by Vim and means "act on the selected area")^
puts the cursor on the first char of the linew
moves to the next wordi"
inserts a"
before the cursor<C-v><Esc>
is Vim's way to input a control character in this context, here it's<Esc>
used to exit insert modeee
moves to the end of the next worda"
appends a"
after the cursor<CR>
executes the command
Using Surround.vim, the command above becomes
:'<,'>norm ^wvees"<CR>
Those are some good out-of-the box solutions given above, but we can also try some plugins which provide multiple cursors like Sublime.
I think this one looks promising:
It seemed abandoned for a while, but has had some contributions in 2014.
It is quite powerful, although it took me a little while to get used to the flow (which is quite Sublime-like but still modal like Vim).
In my experience if you have a lot of other plugins installed, you may meet some conflicts!
There are some others attempts at this feature:
- https://github.com/osyo-manga/vim-over (search-replace only, but with live preview)
- https://github.com/paradigm/vim-multicursor
- https://github.com/felixr/vim-multiedit
- https://github.com/hlissner/vim-multiedit (based on the previous)
- https://github.com/adinapoli/vim-markmultiple
- https://github.com/AndrewRadev/multichange.vim
Please feel free to edit if you notice any of these undergoing improvement.
There are several ways to accomplish that in Vim. I don't know which are most similar to Sublime Text's though.
The first one would be via multiline insert mode. Put your cursor to the second "a" in the first line, press Ctrl-V
, select all lines, then press I
, and put in a doublequote. Pressing <esc>
will repeat the operation on every line.
The second one is via macros. Put the cursor on the first character, and start recording a macro with qa
. Go the your right with llll
, enter insert mode with a
, put down a doublequote, exit insert mode, and go back to the beginning of your row with <home>
(or equivalent). Press j
to move down one row. Stop recording with q
. And then replay the macro with @a
. Several times.
Does any of the above approaches work for you?
if you use the "global" command, you can repeat what you can do on one online an any number of lines.
:g/<search>/.<your ex command>
example:
:g/foo/.s/bar/baz/g
The above command finds all lines that have foo, and replace all occurrences of bar on that line with baz.
:g/.*/
will do on every line
I'm not sure what vim
is doing, but it is an interesting effect. The way you're describing what you want sounds more like how macros work (:help macro
). Something like this would do what you want with macros (starting in normal-mode):
qa
: Record macro toa
register.0w
:0
goto start of line,w
jump one word.i"<Esc>
: Enter insert-mode, insert a"
and return to normal-mode.2e
: Jump to end of second word.a"<Esc>
: Append a"
.jq
Move to next line and end macro recording.
Taken together: qa0wi"<Esc>2ea"<Esc>
Now you can execute the macro with @a
, repeat last macro with @@
. To apply to the rest of the file, do something like 99@a
which assumes you do not have more than 99 lines, macro execution will end when it reaches end of file.
Here is how to achieve what you want with visual-block-mode
(starting in normal mode):
- Navigate to where you want the first quote to be.
- Enter
visual-block-mode
, select the lines you want to affect,G
to go to the bottom of the file. - Hit
I"<Esc>
. - Move to the next spot you want to insert a
"
. - You want to repeat what you just did so a simple
.
will suffice.
Ctrl-v ................ start visual block selection
6j .................... go down 6 lines
I" .................... inserts " at the beginning
<Esc><Esc> ............ finishes start
2fdl. ................. second 'd' l (goes right) . (repeats insertion)
My solution is to use these 2 mappings:
map <leader>n <Esc><Esc>0qq
map <leader>m q:'<,'>-1normal!@q<CR><Down>
How to use them:
- Select your lines. If I want to select the next 12 lines I just press
V12j
- Press
<leader>n
- 회선을 변경하십시오
- 정상 모드인지 확인한 다음
<leader>m
다시 편집하기 위해 다시 선택할 필요는 없습니다. 을 누르고 <leader>n
수정 한 다음을 눌러 <leader>m
적용하십시오.
작동 원리 :
<Esc><Esc>0qq
시각적 선택을 종료하고 줄의 시작 부분으로 이동하여 매크로 기록을 시작하십시오.q
매크로 기록을 중지하십시오.:'<,'>-1normal!@q<CR>
시각적 선택의 시작부터 끝 이전 줄까지 각 줄에서 매크로를 재생합니다.<Down>
마지막 줄로 돌아갑니다.
동일한 키를 다른 모드로 매핑 할 수도 있습니다.
vmap <leader>m <Esc><Esc>0qq
nmap <leader>m q:'<,'>-1normal!@q<CR><Down>
이로 인해 다른 편집 기능을 사용할 수 없게됩니다. 회선을 다시 선택해야합니다.
참고 URL : https://stackoverflow.com/questions/11784408/vim-multiline-editing-like-in-sublimetext
'IT story' 카테고리의 다른 글
MySQL 최대 메모리 사용량 (0) | 2020.08.05 |
---|---|
한 목록의 모든 값을 다른 목록에서 제거 하시겠습니까? (0) | 2020.08.05 |
CSS 그리드를 중심으로 (0) | 2020.08.05 |
사용자 정의 클래스 목록 정렬 (0) | 2020.08.05 |
SQL Server의 연결 시간 초과 (0) | 2020.08.05 |