links: 010 Vim MOC


Use Cases

  • Let’s assume you are working on a react component and you want to make a variation of it, you can copy all the contents of the file and paste in the new file using this technique
  • You want to copy configuration files like .vimrc to another place

Usage

: r is a shortcut for readfilename or rfilename

:r /location/to/the/file/data.txt

This command inserts the contents of the file (ex above is data.txt) starting on the line after the cursor position in the file. If you want to specify a line other than the one the cursor’s on, simply type the line number (or other line address) you want before the read or r command.

The entire contents of /location/to/the/file/data.txt are read(copied) into current working file

To read in the same file and place it after line 185, you would enter:

:185r /location/to/the/file/data.txt

Here are other ways to read in a file:

:$r /location/to/the/file/data.txt

Place the read-in file at the end of the current file.

:0r /location/to/the/file/data.txt

Place the read-in file at the very beginning of the current file.

:0r /location/to/the/file/data.txt

Place the read-in file in the current file, after the line containing pattern.


tags: vim , copy