Read file and insert its content to current buffer

- 1 min

When I am working on projects, I encounter some situations that I need to read all content of a file insert the content to current buffer. Fortunately, vim read command can do it.

:read /etc/issue

Content of /etc/issue, will be added to current buffer starting by current position.

Read command, can be used by its shortcut r. It means the following snippet has the same result as the previous one.

:r /etc/issue

Read command if proceeds with exclamation mark !, it will consider next parameter as bash command. The bash command will be executed and the result will be inserted to current buffer.

Example use cases:

:r! date
:r! cat /etc/passwd | wc -l
:r! pwd

Remember this command. It will save your life.

Mohsen Alizadeh

Mohsen Alizadeh

I am a Software Developer living in Frankf.
My interests span Backend Development with Ruby On Rails && Elixir, System Architecture Design, Sytem Reliability, and System Scalability.

rss facebook twitter github youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora