• 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.
  • 1
    Perhaps this is what you want?
    – dchirikov
    Jan 14, 2013 at 15:59

3 Answers 3


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.

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.


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .