This question already has an answer here:

Always, I am using vim as my text editor. But, when I want to copy full file's content in clipboard to paste another place I open the file in gedit and press CtrlA and then CtrlC.

Opening the file in text editor and pressing CtrlA and then CtrlC is overhead to me. Because I have to open the file in text editor, although I don't edit the file.

So, if there is any command that can copy the file's content in clipboard it better.
clip file.txt

There also a possibility to gain this feature in vim by mapping CtrlA to some command or make a clip command to copy. But, I don't know how to copy entire file in vim using command.

N.B. My vim doesn't support +clipboard.

marked as duplicate by Stephen Kitt, Community Feb 21 '18 at 4:40

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.


xclip will do what you want

xclip -selection clipboard -i <file>

note that -selection clipboard is only needed if you want the file in the clipboard (thats the CtrlC and CtrlV one) if you omit it the files content will be put into the primary buffer (thats the one where you paste by clicking the mousewheel).


A few things you could try here.

1) From vim type in gg"+yG from normal mode, this will bring you to the top of the file, then paste all lines onto the clipboard.

2) You could try catting the file, highlighting it, then using ctrl-insert to copy the highlighted text.

3) As above, but right click on the top bar of the window and look for and Edit/Copy option.

Cheers, Paul T

  • your solution works only inside vim, not for clipboard. – alhelal Feb 21 '18 at 4:29
  • Wrong. The whole idea of "+ is to copy text ONTO THE CLIPBOARD! You can also use "* in place of "+. – Paul T Feb 21 '18 at 4:44
  • Although My vim is in -clipboard features? – alhelal Feb 21 '18 at 4:47
  • Then it won't work for your implementation of vim. Good luck in finding a solution that works for you! – Paul T Feb 21 '18 at 4:49
  • Reading question carefully is better before posting a answer. – alhelal Feb 21 '18 at 4:51

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