Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load another file's content to the current file in Vim?

Tags:

vim

As title, any convenient way?

I especially need it for some cvs/git commit or sendmail to load a template comment. I think it is a vi environment, not Vim.

like image 674
Sam Liao Avatar asked Jul 23 '09 05:07

Sam Liao


People also ask

How do I reload files in VI?

You can use the :edit command, without specifying a file name, to reload the current file. If you have made modifications to the file, you can use :edit! to force the reload of the current file (you will lose your modifications). The command :edit can be abbreviated by :e . The force-edit can thus be done by :e!

Which command inserts text into Vim at the current cursor location?

Bookmark this question. Show activity on this post. To insert text from a file in the current Vim buffer I use :r filename to insert the text below the cursor or :0r filename to insert in the first line.


1 Answers

at the VIM command prompt:

:read new_file 

or for short:

:r new_file 

This will insert the contents of new_file under where the cursor is. For instance if this is the contents of new_file:

 I do not like green eggs and ham  I do not like you sam I am 

And this is the text you're editing:

 I meant what I said and I said what I meant An elephant's faithful one hundred percent. 

And your cursor is on the first line and you type:

:read new_file               

Then your buffer will be:

 I meant what I said and I said what I meant I do not like green eggs and ham  I do not like you sam I am An elephant's faithful one hundred percent. 
like image 80
Nathan Fellman Avatar answered Sep 22 '22 14:09

Nathan Fellman