7

This question already has an answer here:

I want to select all contents of a file and copy it to google chrome. I have tried shift-ctrl-c but it isn't working.

marked as duplicate by muru, karel, Pilot6, Eric Carvalho, Braiam Jun 25 '15 at 16:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

11

From the beginning of the file, type in the key sequence to copy the entire contents to the clipboard:

:%y+

if you want to copy just one line, move the cursor to the start of the line you want, and type in the following key sequence:

:y+

or like stated in another answer here, copy the entire contents to the clipboard + instead of the * registers try:

gg"+yG

for these key sequences to work, you need to have gvim installed, or one similar to it, that will make it so vim has the ability to copy to the clipboard. Below are 3 packages that will enable the +clipboard for vim.

sudo apt-get install vim-gnome

or

sudo apt-get install vim-athena

or

sudo apt-get install vim-gtk

I personally prefer vim-gnome but any of them should work fine.

  • I tried :%y+.. But it is giving an error E850: Invalid register name – In78 Jun 25 '15 at 6:06
  • @In78 If you install vim-gnome, or one of the vim packages like stated in my answer, then it works fine from vim, vi, etc. – Terrance Jun 25 '15 at 6:11
6

Using a pastebin service

pastebinit -i <my_file> -b http://paste.ubuntu.com

You will see an URL. Open the URL in Chrome.

  • Learn something new today. Thank you! +1 – Terrance Jun 25 '15 at 5:45
5

Use the keystrokes below:

gg"*yG

to copy the text to the * or + registers: Explanation:

  • gg
    • gets the cursor to the first character of the file
  • "*y
    • Starts a yank command to the register * from the first line, until...
  • G
    • go the end of the file

Reference:

Shamelessly copied from: https://stackoverflow.com/questions/1620018/copy-all-the-lines-to-clipboard/1620029#1620029

  • 1
    All is open source ;) +1 – A.B. Jun 25 '15 at 5:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.