Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
  • 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
Perhaps this is what you want? – dchirikov Jan 14 '13 at 15:59
up vote 11 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 register (place where yanked text is stored) 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 registers (registers "a and "b in these examples), which I can retrieve with "ap and "bp in the destination file.

share|improve this answer

In insert mode, Press Ctrl + R and then =. Now, you are in command line mode and a 'equal to' sign is shown.


      system('cat filename')

The content of another file 'filename' is pasted in next line of cursor.


Ctrl+R pastes the content of any register. = executes/evaluates the function/expression. Hence, you paste the output of the expression through Ctrl + R and =

cat is a Linux command which shows the content of a file.

Edit: this works in vim, not vi.

share|improve this answer

Your Answer


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.