Vim yanking 라인 범위
저는 최근에 제가 사용할 수있는 도구에 대한 지식을 확장하기로 결정한 C # 개발자입니다. 제가 배우기로 결정한 첫 번째 도구는 Vi / Vim입니다. 지금까지 모든 것이 순조롭게 진행되었지만 답을 찾을 수없는 몇 가지 질문이 있습니다.
여러 줄을 잡아 당기고 싶다고 가정 해 보겠습니다. 여러 가지 방법이 있다는 것을 알고 있지만 줄 번호로하고 싶습니다. 대체 명령이 작동하는 방식과 비슷할 것이라고 생각했습니다
81,91y
. 이를 수행하는 방법이 있습니까?g
일반 모드 의 명령에 대해 약간 혼란 스럽습니다 . 무수히 많은 일을하는 것 같고 g 명령이 핵심에서 수행하는 작업을 실제로 결정할 수 없습니다. 나는 그것이 모션 명령인지 아니면 일반 모드를 통해 실행되는 다른 명령에 대한 일종의 "모두 잡기"인지 혼란 스럽습니다. 누군가 이것을 설명하거나g
명령에 대한 좋은 설명을 제공하는 참조를 알려줄 수 있습니까?
양크 라인 81-91
:81,91y<enter>
손가락이 :
및 ,
키 를 찾는 것을 좋아하지 않는 경우이 방법도 작동합니다 (81 행으로 이동, 11 행을 잡아 당김).
81gg11yy
나의 유일한 용도는 g
입니다 5gg
. 5 번째 줄로 이동합니다. 22gg
: 22 번째 줄. 짐보가 말했듯이 실제로는 다른 명령에 대한 수정 자일뿐입니다.
완전성을 위해 ( http://vim.wikia.com/wiki/Power_of_g )는 g
명령 모드에서 작동 하는 방법을 많이 설명 합니다.
't'를 사용하여 현재 줄을 현재 커서 위치로 복사 할 수도 있습니다.
:81,91t.<enter>
그러면 커서가있는 줄 아래에 81-91 줄이 붙여 넣어집니다.
나는 VIM에 대한 훌륭한 자료 인 http://vimcasts.org 에서 이것을 배웠다 .
또한 vim의 상대 줄 번호 옵션을 사용하는 것을 좋아합니다. 즉, 다음과 같이 입력 할 수 있습니다.
:-10,-7ya a
텍스트를 명명 된 버퍼로 잡아 당기려면 a.
NB A를 지정하면 버퍼 a의 현재 내용에 잡아 당기는 내용이 추가됩니다.
유사한 명령을 사용하여 텍스트 블록을 복사하고 텍스트 블록을 이동할 수도 있다는 것을 잊지 마십시오.
:-10,-7co .
10 행 위의 4 행 텍스트를 현재 행 아래로 복사하는 것을 의미합니다.
:-10,-7mo .
텍스트의 네 줄을 현재 줄 아래로 10 줄 위로 이동하는 것을 의미합니다.
이 G
명령은 개수 값과 함께 제공되는 경우 특정 줄 번호로 이동합니다. 81G
81 번 줄에 연결합니다.
y
명령은 같은 운동과 결합 될 수있다 G
. 따라서 91 행까지 모든 것을 잡아 당기려면 y91G
.
함께하면 다음을 얻을 수 있습니다.
81Gy91G
81 번 줄로 이동 한 다음 91 번 줄로 이동하면서 잡아 당기십시오.
g
그 자체로는 아무것도하지 않습니다. 그것은 일종의 관련없는 명령을 보유하는 몇 가지 메타 명령 중 하나입니다.
z
또 다른 명령입니다.
Vim은 :help index
다음 g
과 같이 설명 합니다.
|g| g{char} extended commands, see |g| below
:help g
목록을 보려면 아래로 스크롤 (또는 )합니다.
가장 좋은 해결책은 v를 눌러 "시각적 모드"로 들어가는 것입니다. 그리고 선을 선택한 후 y를 눌러 복사하십시오. 그런 다음 p를 눌러 복사 한 줄을 붙여 넣습니다.
91에서 96까지의 줄 :91,96y a
( y
)을 레지스터 a
(으로 붙여 넣음)에 추가하는 것 외에도 다음을 사용 하여 얀크 된 줄을 레지스터 에 추가"ap
할 수 있습니다 .
:91,96y A
즉, A
레지스터 의 대문자로 인해 a
덮어 쓰기 대신 레지스터에 추가 작업이 발생합니다 . 레지스터의 대문자는 항상 이와 같이 작동합니다. 예를 들어 레지스터 :let @A=';'
에 a ;
를 추가합니다 a
.
더하기 (+) 또는 빼기 (-) 사용은 현재 커서 위치를 기준으로 행을 참조합니다.
:-10,+10y b
즉 y
, 현재 커서 위치 주위에 21 줄을 yank ( )하고 register에 넣습니다 b
.
An absence of input actually represents the current cursor position as well, which means that this:
:-5,y a
would yank the text from 5 lines above to current cursor position into named buffer a
, and:
:,+5y a
would yank the 5 lines after the current cursor position into buffer a
.
Note: If you have a macro in buffer a
it was just overwritten by the previous yank, as yank registers and macro registers are really the same thing. Which is why, coincidentally, you can paste a macro, edit it, and then yank it back into it's register. I personally use letters reached by my left hand for yanks, and letters reached by my right hand for macros.
Moving blocks of text around, looks like this:
:+10,+13m.
which means move the four lines positioned 10 lines ahead of current cursor, to below the current line.
Addendum
I previously confused ya
in :91,95ya a
to be somehow synonymous with ya{motion}
where the motion was supplied by 91,95
. This was incorrect and the "a" in ya
is completely unnecessary. In my defense, my help yank
does not convey that ya
is a possible alias of yank
.
As a long time Vi/Vim user I tend to use 'marks' instead of line numbers (or 'line markers'). It works like this: m
is the 'mark' character; then use any letter to identify/name the mark. To return to a mark preface the named mark with a single quote ( 'a
)These marks can be used as the range. Examples:
File:
<line 1>
<line 2>
<line 3>
<line 4>
<line 5>
When in command mode move cursor to line 2, typema
. scroll to line 4, typemb
. To yank from mark a to mark b type:
:'a,'byank
To delete from mark a to mark b type:
:'a,'bdel
To search from mark a to mark b and replace 'ine' with 'ink':
:'a,'bs/ine/ink/g
To copy mark a through mark b and paste below the current position (the 'dot' always references the line where the cursor currently is positioned):
:'a,'bco .
Shift lines of code, between mark a through mark b, one tab to the right (use opposite chevron, <
, to move left):
:'a,'b>
In command mode you can move back to marks by simply typing 'a
to move back to the line marked a
. Typing ''
moves you back to previous position (unfortuantely only remembers the previous position, not two back).
You can yank to named buffers, copy, delete lines, search&replace just portions of your code, etc. without needing to know the line numbers.
참고URL : https://stackoverflow.com/questions/2023015/vim-yanking-range-of-lines
'Nice programing' 카테고리의 다른 글
콜백 함수를 실행할 때 Angular2 구성 요소의 "this"가 정의되지 않았습니다. (0) | 2020.10.18 |
---|---|
.NET Framework에서 람다와 대리자의 차이점은 무엇입니까? (0) | 2020.10.18 |
Django 관리 인터페이스의 읽기 전용 모델? (0) | 2020.10.18 |
비취 / 퍼그 댓글 (0) | 2020.10.18 |
DLL에서 동적으로 함수로드 (0) | 2020.10.18 |