- 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.
Type the following
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
- Open 2nd file using
- do a normal
yy(yank) commands in the other file
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.
In insert mode, Press Ctrl + R and then =. Now, you are in command line mode and a 'equal to' sign is shown.
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
cat is a Linux command which shows the content of a file.
Edit: this works in vim, not vi.