(Move categories to tip template) |
(Remove html character entities) |
||
Line 41: | Line 41: | ||
And because this puts the entire results of the system command on a single line separated by ^@, I need to split the lines up: |
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/\ |
+ | silent! exec "%s/\<CR>/\<CR>/g" |
− | silent! exec "%s/\ |
+ | 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) |
The worst thing was when the results were really large (try running %s on a single 6Mb line... not pleasant) |
Revision as of 08:21, 28 September 2008
Tip 40 Printable Monobook Previous Next
created March 8, 2001 · complexity basic · author Anon · version 5.7
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