development

시스템의 클립 보드에서 vim 붙여 넣기 (및 복사)하는 방법은 무엇입니까?

big-blog 2020. 9. 30. 09:20
반응형

시스템의 클립 보드에서 vim 붙여 넣기 (및 복사)하는 방법은 무엇입니까?


다른 편집기와 달리 vim은 복사 된 텍스트를 자체 클립 보드에 저장합니다. 그래서 웹 페이지에서 일부 텍스트를 복사하여 현재 작업 파일에 붙여 넣기가 매우 어렵습니다. 그래서 gedit를 열거 나 수동으로 입력해야합니다.

시스템 클립 보드에서 vim 붙여 넣기를 할 수 있습니까?


"*"+레지스터는 시스템의 클립 보드위한 것입니다 ( :help registers). 시스템에 따라 다른 작업을 수행 할 수 있습니다. 예를 들어 OSX 또는 Windows와 같이 X11을 사용하지 않는 시스템에서 "*레지스터는 시스템 클립 보드를 읽고 쓰는 데 사용됩니다. X11 시스템에서는 두 레지스터를 모두 사용할 수 있습니다. 자세한 내용은 :help x11-selection을 참조하십시오. 그러나 기본적으로 이것은 "*X11의 PRIMARY 선택 (일반적으로 마우스로 선택한 항목을 복사하고 마우스 가운데 버튼으로 붙여 넣기)과 "+유사하며 X11의 CLIPBOARD 선택 ( 클립 보드에 해당함 )과 유사합니다 .

당신의 머리를 가서 모든 경우, 사용 시도 "*yy또는 "+yy시스템의 클립 보드에 줄을 복사 할 수 있습니다. 적절한 컴파일 옵션이 있다고 가정하면 둘 중 하나가 작동합니다. 이를 더 편리한 것으로 다시 매핑 할 수 있습니다. 예를 들어 vnoremap <C-c> "*y~ / .vimrc에 넣어 시각적으로 선택하고 Ctrl+ c눌러 시스템의 클립 보드로 이동할 수 있습니다 .

복사 / 시스템 클립 보드에서 붙여 넣기주의하십시오 작업을하지 않을 경우 :echo has('clipboard')이 경우, 정력에 반환 0이 컴파일되지 않는 +clipboard기능과 다른 버전을 설치하거나 다시 컴파일해야합니다. 일부 Linux 배포판은 기본적으로 최소 vim 설치를 제공하지만 일반적으로 또는 패키지설치vim-gtkvim-gtk3 하면 추가 기능을 얻을 수 있습니다.

'clipboard'설명 옵션을 살펴볼 수도 있습니다 :help cb. 이 경우 수 :set clipboard=unnamed또는 :set clipboard=unnamedplus작업이 자동으로 시스템 클립 보드에 복사 / 삭제 모든 확 잡아 당기는를 확인합니다. 이것은 클립 보드에 다른 것을 저장하는 경우에 불편을 줄 수 있습니다.

붙여 넣으려면 "+p또는 "*p(다시 시스템 및 / 또는 원하는 선택에 따라)를 사용하거나 다른 항목에 매핑 할 수 있습니다. 명시 적으로 입력하지만 종종 삽입 모드에 있습니다. 당신이 삽입 모드에 있다면 당신은 여전히 사용하여 적절한 들여 쓰기로 붙여 넣을 수 있습니다 <C-r><C-p>*또는 <C-r><C-p>+. 을 참조하십시오 :help i_CTRL-R_CTRL-P.

vim의 paste옵션 ( :help paste) 도 언급 할 가치가 있습니다. 이렇게하면 vim이 여러 다른 옵션을 비활성화하는 특수 "붙여 넣기 모드"로 전환되어 터미널 에뮬레이터 또는 멀티플렉서의 친숙한 붙여 넣기 단축키를 사용하여 쉽게 vim에 붙여 넣을 수 있습니다. :set paste활성화하려면 입력 하고 콘텐츠를 붙여 넣은 다음 입력 :set nopaste하여 비활성화하면됩니다. 또는 pastetoggle옵션을 사용 하여 모드 ( :help pastetoggle) 를 토글하는 키 코드를 설정할 수 있습니다 . 이러한 옵션 대신 레지스터를 사용하는 것이 좋지만 여전히 너무 무섭다면 vim chops를 완성하는 동안 편리한 해결 방법이 될 수 있습니다.

자세한 :help clipboard내용은를 참조하십시오.


gnome-terminal의 붙여 넣기 단축키로 vim에 복사 할 수 있습니다. 삽입 모드에서 파일을 만들고 사용

Ctrl+ Shift+ v.

미리 기억하십시오

 :set paste 

들여 쓰기를 엉망으로 만드는 것을 방지합니다.


리눅스

내 Linux 시스템에서 +*레지스터는 마우스 가운데 버튼으로 붙여 넣을 수있는 X11 선택 항목에 매핑됩니다. :set clipboard=unnamed:set clipboard=unnamedplus사용 후 레지스터는 클립 보드에 매핑하고, CTRL-V로 붙여 넣을 수 있습니다.

세부 사항은 다소 구성 및 시스템에 따라 다르므로 마일리지는 확실히 다를 것입니다. 그래도 올바른 방향으로 안내해야합니다.

또한보십시오

http://vim.wikia.com/wiki/Accessing_the_system_clipboard


내 구성은 복사 및 붙여 넣기를 위해 작동합니다.

" copy and paste
vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa

이 목적을 위해 vimrc에서 필요한 라인입니다.

set clipboard+=unnamed  " use the clipboards of vim and win
set paste               " Paste from a windows or from vim
set go+=a               " Visual selection automatically copied to the clipboard

나는이 질문이 더 객관적인 대답을 할 가치가 있다고 믿습니다.

붙여 넣기 모드 들어가기

  • ESC
  • : 세트 붙여 넣기
  • 프레스 i
  • SHIFT+ Insert(클립 보드에 복사 된 텍스트 포함)


Leaving Paste Mode

  • ESC
  • :set nopaste
  • press i

You pasted the text and you're able to type again.


clipboard

There is a special register for storing this selection, it is the "* register. Nothing is put in here unless the information about what text is selected is about to change (e.g. with a left mouse click somewhere), or when another application wants to paste the selected text. Then the text is put in the "* register. For example, to cut a line and make it the current selection/put it on the CLIPBOARD:

    "*dd

Similarly, when you want to paste a selection from another application, e.g., by clicking the middle mouse button, the selection is put in the "* register first, and then 'put' like any other register. For example, to put the selection (contents of the CLIPBOARD):

    "*p

registers E354

> There are nine types of registers:                      
> 1. The unnamed register ""
> 2. 10 numbered registers "0 to "9
> 3. The small delete register "-
> 4. 26 named registers "a to "z or "A to "Z
> 5. four read-only registers ":, "., "% and "#
> 6. the expression register "=
> 7. The selection and drop registers "*, "+ and "~ 
> 8. The black hole register "_
> 9. Last search pattern register "/

Paste from clipboard

1. Clipboard: Copy
2. Vim insertmode, middle mouse key

Check for X11-clipboard support in terminal

When you like to run Vim in a terminal you need to look for a version of Vim that was compiled with clipboard support. Check for X11-clipboard support, from the console, type:

% vim --version

If you see "+xterm_clipboard", you are good to go.

http://vim.wikia.com/wiki/Accessing_the_system_clipboard

The X server maintains three selections, called:

PRIMARY, SECONDARY and CLIPBOARD

The PRIMARY selection is conventionally used to implement copying and pasting via the middle mouse button. The SECONDARY and CLIPBOARD selections are less frequently used by application programs.

http://linux.die.net/man/1/xsel


I tried the suggestions above and none of them worked in my environment. (Windows PuTTY clone over ssh)

Some additional googling turned up: https://unix.stackexchange.com/questions/110684/copy-paste-into-sshd-vim-from-local-windows-clipboard

One of the comments suggested using SHIFT+INSERT which did the trick for pasting from my desktop's clipboard into Vim's buffer. Ctrl-C was already working to copy to the desktop's clipboard from Vim.


Didn't have +clipboard so I came up with this alternative solution using xsel:

Add to your ~/.vimrc:

vnoremap <C-C> :w !xsel -b<CR><CR>


A quick note for people whose vim installation does not support the * and + registers. It is not necessary to download a new vim installation to paste from the clipboard. Here is an alternative method:

1) Install parcellite (a clipboard manager with a low memory footprint);

2) In your .vimrc file, add the following:

command Clip r !parcellite -c

3) Restart vim.

Now when you type in :Clip as an ex command, the contents of the clipboard will be pasted in at the cursor. You can also map the new command to a function key so as to be able to do this with one keystroke.


This works for me: Ctrl+Shift+V


Following on from Conner's answer, which was great, but C-R C-p + and C-R C-p * in insert mode is a bit inconvenient. Ditto "*p and "+p from command mode.

a VIM guru suggested the following to map C-v to what C-r C-p + does.

You could have :inoremap <C-v> <C-o>"+p for insert mode only

if you really wanted to override blockwise visual mode (not recommended by him as visual mode is good) you could have map <C-v> "+p


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-vim

install gui verion of vim:

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

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.


On top of the setting :set clipboard=unnamed, you should use mvim -v which you can get with brew install macvim if you're using vim on Terminal.app on Mac OS X 10.9. Default vim does not support clipboard option.


It may also be worth mentioning, on OSX using Vim, you can select text with the mouse, Cmd-C to copy to OSX system clipboard, and the copied text will be available in the clipboard outside of Vim.

In other words, OSX treats it like it were a regular window, and this is where the much-maligned Apple "Command" button comes in handy.

B-30


Based on @lis2 answer, I use a simpler configuration that will not force Insert mode at the end:

" Copy and paste
if has('clipboard') && !has('gui_running')
  vnoremap <C-c> "+y
  vnoremap <C-x> "+d
  vnoremap <C-v> "+p
  inoremap <C-v> <C-r><C-o>+
endif

Mind that all these override default Vim mappings:

  • v_CTRL-C: stop Visual mode
  • v_CTRL-X: subtract [count] from number
  • v_CTRL-V: blockwise Visual mode
  • i_CTRL-V: insert next non-digit literally, which is also mapped to i_CTRL-Q

As an alternative, one can use keys inspired in the "yank", "delete" and "put" Vim verbs: <C-y>, <C-d> and <C-p> respectively. These would only override one default mapping:

  • i_CTRL-P: backwards search keyword for completion

The other solutions are good if you want to change your vimrc, etc... However I wanted an simple way to copy from vim to my system keyboard. This is what I came up with.

  • Select the text you want to copy with visual mode v
  • Press : (it will automatically expand to show :'<,'>)
  • Type y * or y + (depending on your system) to yank the selected text to the system clipboard

What you really need is EasyClip. It will do just that and so much more...


The simplest solution to this, that also works between different Linux machines through ssh is:

  1. Check whether vim supports X-11 clipboard: vim --version | grep clipboard. If it reports back -clipboard and -xterm_clipboard you should install either vim-gtk or vim-gnome (gvim on arch linux)

  2. Add the following lines to your .vimrc:

set clipboard=unnamedplus
set paste
  1. If you login on a different machine via ssh, use the option -Y: ssh -Y machine

Now copying and pasting should work exactly as expected on a single, and across different machines by only using y for yank and p for paste. NB modify .vimrc on all machines where you want to use this feature.


If you are using a mouse first do

 :set paste 

Then right click mouse and the contents in buffer will be pasted


With Vim 8+ on Linux or Mac, you can now simply use the OS' native paste (ctrl+shift+V on Linux, cmd+V on Mac). Do not press i for Insert Mode.

It will paste the contents of your OS clipboard, preserving the spaces and tabs without adding autoindenting. It's equivalent to the old :set paste, i, ctrl+shift+V, esc, :set nopaste method.

You don't even need the +clipboard or +xterm_clipboard vim features installed anymore. This feature is called "bracketed paste". For more details, see Turning off auto indent when pasting text into vim


I ran into this issue on a mid-2017 Macbook Pro running vim within iTerm2 as my primary development environment.

As other answers have suggested, I ran vim --version and noticed that it returns -clipboard, which means that the version of vim that shipped with my machine hasn't been compiled with the clipboard option.

The homebrew package for vim appears to compile with the clipboard option, so the fix for me was to:

  1. Run brew install vim
  2. Add set clipboard+=unnamed to my ~/.vimrc file
  3. Close and reopen iTerm2

When I use my Debian vim that is not integrated with Gnome (vim --version | grep clip # shows no clipboard support), I can copy to the clipboard after holding the Shift key and selecting the text with the mouse, just like with any other curses program. As I figured from a comment by @Conner, it's the terminal (gnome-terminal in my case) that turns off its mouse event reporting when it senses my Shift press. I guess curses-based programs can receive mouse events after sending a certain Escape sequence to the terminal.


If you are on windows and you want to paste contents of system clipboard using p then type this command.

:set clipboard = unnamed

This solved my problem.


There are two simple ways to do this. Make your file in insert mode and 1) press the middle button (the scroll wheel) in your mouse, or 2) Ctrl + Shift + V


For some international keyboards, you may need to press "+Space to get a ".

So in those case you would have to press "Space+y or "Space*y to copy.

And "Space+p or " Space*p to paste.


Since vim 8 right click enables visual mode by default. This prevents the "normal" copy & paste (call it a "defect by design" https://github.com/vim/vim/issues/1326). Fix it by doing:

echo "set mouse-=a" >> ~/.vimrc .

Exit and restart vim.


Copy To OS Clipboard

Select text in visual mode, press "*y

Paste From OS Clipboard

Press "*p

참고URL : https://stackoverflow.com/questions/11489428/how-to-make-vim-paste-from-and-copy-to-systems-clipboard

반응형