Tuesday, April 30, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 8897  / 2 Years ago, fri, march 4, 2022, 3:22:16

I can cat a file, copy and paste text with the middle button or shift-insert.



How can I copy text in vim and paste it from the system clipboard?


More From » vim

 Answers
2

You need to have Vim with the clipboard and xtermclipboard features compiled in. In Ubuntu, these are only available with the vim GUI packages (vim-gnome, vim-gtk, vim-athena, etc.).



Once you install one of these, you can copy to (and paste from) the clipboard registers (* and +). From this very informative post on Vi and Vim:




For X11-based systems (ie. Linux and most other UNIX-like
systems) there are 2 clipboards, which are independent of each other:




  • PRIMARY - This is copy-on-select, and can be pasted with the middle mouse button.

  • CLIPBOARD - This is copied with (usually) ^C, and pasted with ^V (It's like MS Windows).






Vim has 2 special registers corresponding to these clipboards:




  • * uses PRIMARY; mnemonic: star is select (for copy-on-select)

  • + uses CLIPBOARD; mnemonic: CTRL + C (for the common keybind)




To copy to a register, you precede the copy command (y) with " and the name of the register (*, for example). "*y, then middle-click to paste, or "+y and ShiftInsert to paste.


[#20390] Saturday, March 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amencisiv

Total Points: 9
Total Questions: 102
Total Answers: 118

Location: Tajikistan
Member since Tue, Mar 21, 2023
1 Year ago
;