Vim Tips Wiki
(change "anon" author to blank; trim "created" date; minor manual clean)
(Undo revision 38271 by 176.26.21.225 (talk))
Tag: sourceedit
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
|complexity=basic
 
|complexity=basic
 
|author=
 
|author=
|version=5.7
+
|version=6.0
 
|rating=60/24
 
|rating=60/24
|category1=Automated_Text_Insertion
+
|category1=Automated Text Insertion
 
|category2=
 
|category2=
 
}}
 
}}
Use the <tt>:read</tt> command to insert a file, or the output from a system command, into the current buffer. Examples:
+
Use the <code>:read</code> command to insert a file, or the output from a system command, into the current buffer. Examples:
 
<pre>
 
<pre>
 
:r foo.txt Insert the file foo.txt below the cursor.
 
:r foo.txt Insert the file foo.txt below the cursor.

Latest revision as of 21:45, 5 April 2015

Tip 40 Printable Monobook Previous Next

created 2001 · complexity basic · version 6.0


Use the :read command to insert a file, or the output from a system command, into the current buffer. Examples:

:r foo.txt    Insert the file foo.txt below the cursor.
:0r foo.txt   Insert the file foo.txt before the first line.
:r !ls        Insert a directory listing below the cursor.
:$r !pwd      Insert the current working directory below the last line.

On Windows, the last two commands would be:

:r !dir
:$r !cd

References[]

Comments[]

Don't know the path to perl (for #!/.../perl)?

:r !which perl

I now no longer need to use "append system" code in my scripts. I used to use code like:

call append(line("."), system(l:cmd))

And because this puts the entire results of the system command on a single line separated by ^@, I need to split the lines up:

silent! exec "%s/\<CR>/\<CR>/g"
silent! exec "%s/\<NL>/\<CR>/g"

The worst thing was when the results were really large (try running %s on a single 6Mb line... not pleasant) I can now just use

exec "r !".l:cmd