Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
  • I am editing file 'A' in vi.
  • I have another file 'B' whose contents I want to 'paste' into my current location.
  • Other than actual mouse copy and pasting, is there a command that I can use that will pull in the content of another file to my current edit location.
share|improve this question
1  
Perhaps this is what you want? –  dchirikov Jan 14 '13 at 15:59

2 Answers 2

up vote 10 down vote accepted

Type the following

:r filename_to_paste

This will paste the contents of the file after the line on which the cursor is present.


If you need to copy/paste smaller range of lines/block of text from one file to other, you can also do the following assuming one file is opened in vim already

  • Open 2nd file using :sp (split) or :vsp(vertical split)
  • do a normal yy (yank) commands in the other file
  • do p (paste) command back in the 1st file, as the buffer is common to both the files.
  • Press Ctrl+w twice to switch between splited files.
share|improve this answer
    
Looks good. Will accept soon. –  Michael Durrant Jan 14 '13 at 15:58

That :r filename is the shortest for whole files. If you want only one more small portions, I always go to the source file and use 'a57Y 'b12Y to copy specific lines to buffers, which I can retrieve with 'ap and 'bp in the destination file.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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