< Previous | Contents | Next >
Inserting An Entire File Into Another
It's also possible to insert an entire file into one that we are editing. To see this in action, let's end our vi session and start a new one with just a single file:
[me@linuxbox ~]$ vi ls-output.txt
[me@linuxbox ~]$ vi ls-output.txt
We will see our file listing again:
total 343700
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
31316 2015-12-05 08:58 [
8240 2015-12-09 13:39 411toppm
111276 2016-01-31 13:36 a2p
25368 2014-10-06 20:16 a52dec
11532 2015-05-04 17:43 aafire
7292 2015-05-04 17:43 aainfo
total 343700
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
Move the cursor to the third line, then enter the following ex command:
:r foo.txt
:r foo.txt
The :r command (short for “read”) inserts the specified file before the cursor position. Our screen should now look like this:
total 343700
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
31316 2015-12-05 08:58 [
8240 2015-12-09 13:39 411toppm
total 343700
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
The quick brown fox jumped over the lazy dog. It was cool.
Line 2
Line 3
Line 4
Line 5
-rwxr-xr-x 1 root root 111276 2016-01-31 13:36 a2p
-rwxr-xr-x 1 root root 25368 2014-10-06 20:16 a52dec
-rwxr-xr-x 1 root root 11532 2015-05-04 17:43 aafire
-rwxr-xr-x 1 root root 7292 2015-05-04 17:43 aainfo
The quick brown fox jumped over the lazy dog. It was cool.
Line 2
Line 3
Line 4
Line 5
-rwxr-xr-x 1 root root 111276 2016-01-31 13:36 a2p
-rwxr-xr-x 1 root root 25368 2014-10-06 20:16 a52dec
-rwxr-xr-x 1 root root 11532 2015-05-04 17:43 aafire
-rwxr-xr-x 1 root root 7292 2015-05-04 17:43 aainfo