your programing

잡아 당긴 텍스트를 Vim 명령 줄에 붙여 넣는 방법은 무엇입니까?

lovepro 2020. 10. 3. 11:25
반응형

잡아 당긴 텍스트를 Vim 명령 줄에 붙여 넣는 방법은 무엇입니까?


잡아 당긴 텍스트를 Vim 명령 줄에 붙여넣고 싶습니다. 가능할까요?


예. 히트 Ctrl- R다음 ". 당신은 당신이 빠지게 것을 리터럴 제어 문자가있는 경우, 사용 Ctrl- R, Ctrl- O, ".

다음은 레지스터로 수행 할 수있는 작업에 대한 설명입니다. 레지스터로 할 수있는 일은 대단한 일이며 일단 사용 방법을 알게되면 레지스터 없이는 살 수 없습니다.

레지스터는 기본적으로 문자열의 저장 위치입니다. Vim에는 다양한 방식으로 작동하는 많은 레지스터가 있습니다.

  • 0(yank register : 레지스터 y를 지정하지 않고 일반 모드에서 사용할 때 , yanked 텍스트가 거기로 이동하고 기본 레지스터에도),
  • 1to 9(삭제 레지스터 이동, c또는 같은 명령을 사용하면 d삭제 된 항목이 레지스터 1로 이동하고, 레지스터 1에 있던 항목이 레지스터 2로 이동하는 ),
  • "(기본 레지스터, 명명되지 않은 레지스터라고도합니다. 여기 "에서 Ctrl- R, "),
  • az자신의 사용 (대문자 A하기 Z위해 해당 레지스터에 추가된다).
  • _( /dev/null(Unix) 또는 NUL(Windows) 와 같이 작동하며 쓸 수는 있지만 버려지고 읽을 때 항상 비어 있음),
  • - (작은 삭제 레지스터),
  • /(당신이 텍스트를 찾을 때 검색 패턴 레지스터, 업데이트 /, ?, *또는 #예를 들어, 당신은 동적 검색 패턴을 변경하는 데에 쓸 수 있습니다)
  • :( Q또는 :, 읽기 전용을 통해 마지막으로 입력 한 VimL 명령 저장 ),
  • +*(시스템 클립 보드 레지스터, 클립 보드를 설정하고 클립 보드 내용을 읽을 수 있습니다.)

참조 :help registers전체 참조.

언제든지 :registers모든 레지스터의 내용을 표시하는 데 사용할 수 있습니다. 이 명령의 동의어와 약어는 :display, :reg:di입니다.

삽입 또는 명령 줄 모드에서 Ctrl- R레지스터 이름과 함께이 레지스터의 내용을 삽입합니다. 문자 그대로 삽입하려면 (자동 들여 쓰기, 0x08백 스페이스 등 의 제어 문자 변환 없음 ) Ctrl- R, Ctrl- O, 레지스터 이름을 사용할 수 있습니다 . 자세한 내용은 :help i_CTRL-R다음 단락을 참조하십시오.

그러나 다음을 수행 할 수도 있습니다 (그리고 레지스터에 대한 많은 용도를 잊었을 것입니다).

  • 일반 모드에서 ":p. vim에서 사용한 마지막 명령은 버퍼에 붙여 넣습니다.
    Let 's decompose : "다음 yank, delete 또는 paste 작업 중에 사용할 레지스터를 선택할 수있는 Normal 모드 명령입니다. 따라서 ":콜론 레지스터를 선택합니다 (마지막 명령 저장). 다음 p은 이미 알고있는 명령이며 레지스터의 내용을 붙여 넣습니다.

    cf. :help ",:help quote_:

  • VimL 파일 (예 :)을 편집하고 있으며 .vimrc지금 바로 두 개의 연속 행을 실행하고 싶습니다 yj:@"Enter.
    여기에서 yj현재와 ​​다음 라인을 기본 레지스터 (이름없는 레지스터라고도 함)에 홱 잡아 당깁니다 (이는 j가 라인 단위 모션이지만이 답변의 범위를 벗어나기 때문입니다). 그런 다음 :@Ex 명령은 인수로 지정된 레지스터에 저장된 Ex 명령을 재생 "하고 이름이 지정되지 않은 레지스터를 참조하는 방법입니다. 또한 관련된이 답변의 상단을 참조하십시오.

    "여기에 사용 된 (레지스터 이름) "이전 예의 일반 모드 명령 혼동하지 마십시오 .

    cf. :help :@:help quote_quote

  • 마지막 검색 패턴을 삽입 모드에서 파일에 삽입하거나 Ctrl- R, 를 사용하여 명령 줄에 삽입합니다 /.

    cf. :help quote_/,help i_CTRL-R

    추론 : 검색 패턴을 유지하지만, 대안을 추가 : / Ctrl- R, / \|alternative.

  • 시각적 모드에서 줄 중간에있는 두 단어를 선택하고으로 잡아 당기면 y이름이 지정되지 않은 레지스터에 있습니다. 이제 현재 위치 바로 아래에 다음 두 단어가 포함 된 새 줄을 열려고합니다 :pu.. 이것은 :put ". :put명령은, 많은 예 명령처럼 만 라인 방식으로 작동합니다.

    cf. :help :put

    :call setreg('"', @", 'V')다음 같이 할 수도 있습니다 p. setreg함수는 두번째 인자의 내용으로 초기화 (및 이름으로 변수로 레지스터를 사용하여 이름이 (a 문자열) 첫 번째 인수로 주어진 어느 레지스터를 설정 VimL의 레지스터 이름), 및 라인 단위의 경우 세 번째 인수에 지정된 모드로, 문자 단위의 경우 아무것도, 블록 단위의 경우 리터럴 바꿉니다 .@xxV^V

    cf. :help setreg(). 역 기능은 getreg()getregtype()입니다.

  • 당신이 매크로를 기록하는 경우 qa... q다음 :echo @a사용자가 입력 한 내용을 말할 것입니다, 그리고 @a(아마도 당신이 그 일을 알고 반복적 인 작업을 피하기 위해 매우 유용) 매크로를 재생합니다

    cf. :help q,help @

    Corollary from the previous example: If you have 8go in the clipboard, then @+ will play the clipboard contents as a macro, and thus go to the 8th byte of your file. Actually this will work with almost every register. If your last inserted string was dd in Insert mode, then @. will (because the . register contains the last inserted string) delete a line. (Vim documentation is wrong in this regard, since it states that the registers #, %, : and . will only work with p, P, :put and Ctrl-R).

    cf. :help @

    Don't confuse :@ (command that plays Vim commands from a register) and @ (normal-mode command that plays normal-mode commands from a register).

    Notable exception is @:. The command register does not contain the initial colon neither does it contain the final carriage return. However in Normal mode, @: will do what you expect, interpreting the register as an Ex command, not trying to play it in Normal mode. So if your last command was :e, the register contains e but @: will reload the file, not go to end of word.

    cf. :help @:

  • Show what you will be doing in Normal mode before running it: @='dd' Enter. As soon as you hit the = key, Vim switches to expression evaluation: as you enter an expression and hit Enter, Vim computes it, and the result acts as a register content. Of course the register = is read-only, and one-shot. Each time you start using it, you will have to enter a new expression.

    cf. :help quote_=

    Corollary: If you are editing a command, and you realize that you should need to insert into your command line some line from your current buffer: don't press Esc! Use Ctrl-R =getline(58) Enter. After that you will be back to command line editing, but it has inserted the contents of the 58th line.

  • Define a search pattern manually: :let @/ = 'foo'

    cf. :help :let

    Note that doing that, you needn't to escape / in the pattern. However you need to double all single quotes of course.

  • Copy all lines beginning with foo, and afterwards all lines containing bar to clipboard, chain these commands: qaq (resets the a register storing an empty macro inside it), :g/^foo/y A, :g/bar/y A, :let @+ = @a.

    Using a capital register name makes the register work in append mode

    Better, if Q has not been remapped by mswin.vim, start Ex mode with Q, chain those “colon commands” which are actually better called “Ex commands”, and go back to Normal mode by typing visual.

    cf. :help :g, :help :y, :help Q

  • Double-space your file: :g/^/put _. This puts the contents of the black hole register (empty when reading, but writable, behaving like /dev/null) linewise, after each line (because every line has a beginning!).

  • Add a line containing foo before each line: :g/^/-put ='foo'. This is a clever use of the expression register. Here, - is a synonym for .-1 (cf. :help :range). Since :put puts the text after the line, you have to explicitly tell it to act on the previous one.

  • Copy the entire buffer to the system clipboard: :%y+.

    cf. :help :range (for the % part) and :help :y.

  • If you have misrecorded a macro, you can type :let @a=' Ctrl-R =replace(@a,"'","''",'g') Enter ' and edit it. This will modify the contents of the macro stored in register a, and it's shown here how you can use the expression register to do that.

  • If you did dddd, you might do uu in order to undo. With p you could get the last deleted line. But actually you can also recover up to 9 deletes with the registers @1 through @9.

    Even better, if you do "1P, then . in Normal mode will play "2P, and so on.

    cf. :help . and :help quote_number

  • If you want to insert the current date in Insert mode: Ctrl-R=strftime('%y%m%d')Enter.

    cf. :help strftime()

Once again, what can be confusing:

  • :@ is a command-line command that interprets the contents of a register as vimscript and sources it
  • @ in normal mode command that interprets the contents of a register as normal-mode keystrokes (except when you use : register, that contains last played command without the initial colon: in this case it replays the command as if you also re-typed the colon and the final return key).

  • " in normal mode command that helps you select a register for yank, paste, delete, correct, etc.

  • " is also a valid register name (the default, or unnamed, register) and therefore can be passed as an arguments for commands that expect register names

For pasting something that is the system clipboard you can just use SHIFT - INS.

It works in Windows, but I am guessing it works well in Linux too.


"I'd like to paste yanked text into Vim command line."

While the top voted answer is very complete, I prefer editing the command history.

In normal mode, type: q:. This will give you a list of recent commands, editable and searchable with normal vim commands. You'll start on a blank command line at the bottom.

For the exact thing that the article asks, pasting a yanked line (or yanked anything) into a command line, yank your text and then: q:p (get into command history edit mode, and then (p)ut your yanked text into a new command line. Edit at will, enter to execute.

To get out of command history mode, it's the opposite. In normal mode in command history, type: :q + enter


For pasting something from the system clipboard into the vim command line ("command mode"), use Ctrl+R followed by +. For me, at least on Ubuntu, Shift+Ins is not working.

PS: Not sure why Ctrl+R followed by *, which is theoretically the same as Ctrl+R followed by + doesn't seem to work always. I searched and discovered the + version and it seems to work always, at least on my box.


It's worth noting also that the yank registers are the same as the macro buffers. In other words, you can simply write out your whole command in your document (including your pasted snippet), then "by to yank it to the b register, and then run it with @b.


I was having a similar problem. I wanted the selected text to end up in a command, but not rely on pasting it in. Here's the command I was trying to write a mapping for:

:call VimuxRunCommand("python")

The docs for this plugin only show using string literals. The following will break if you try to select text that contains doublequotes:

vnoremap y:call VimuxRunCommand("<c-r>"")<cr>

To get around this, you just reference the contents of the macro using @ :

vnoremap y:call VimuxRunCommand(@")<cr>

Passes the contents of the unnamed register in and works with my double quote and multiline edgecases.


OSX

If you are using vim in MAC OSX, unfortunately it comes with older verion, and not complied with clipboard options. Luckily, homebrew can easily solve this problem.

install vim:

brew install vim --with-lua --with-override-system-vi

install gui verion of vim:

brew install macvim --with-lua --with-override-system-vi

restart the terminal to take effect.


append the following line to ~/.vimrc
set clipboard=unnamed

now you can copy the line in vim with yy and paste it system-wide.


this question is pretty old, but since it has been viewed so many times, it seems to be popular - i'll put this here for posterity. for context, this info comes from out-of-the-box, no plugins, no .vimrc vim 7.4 behavior in linux mint with the default options.

you can always select text with the mouse (or using V or v and placing the selection in the "* register), and paste it into the command line with SHIFT-CTL-v.

typing CTL-r in the command line will cause a prompt for a register name. so typing :CTL-r* will place the content register * into the command line. it will paste any register, not just "*. see :help c_CTRL-R .

furthermore, the middle mouse button will paste into the command line. see :help->quote-plus for a description of the how x11 deals with selection. even in a plain, outta-the-box vim (again, in vim 7.4 in linux mint, anyway), any selection made with the left mouse button can be pasted in the command line with the middle mouse button.

in addition, the middle mouse button will also paste text selected in vim into many other x11 applications, even gui ones (eg., firefox, thunderbird) and pasting text into the command line is also possible where the text was selected from other apps.

see :help->x11-selection for addl info.

tl;dr

try the :CTL-r approach first, then use SHIFT-CTL-v or the middle mouse button if you need something else.

it is conceded that it can be confusing.


  1. "[a-z]y copy text to [a-z] register;

  2. use :!go to edit command;

  3. CTRL+R follow the register identity to paste what you copy.

It used to CentOS7.

참고URL : https://stackoverflow.com/questions/3997078/how-to-paste-yanked-text-into-vim-command-line

반응형