Thomas Klausner
2014-04-27 15:40:32 UTC
Hi!
For commit scripting purposes, I'd like to prefill a temporary file
(which I can't influence directly) with the contents of another file.
Using vi, I'm so far using
EDITOR="vi -c 'r /home/wiz/template'"
which then will expand to
vi -c 'r /home/wiz/template' /tmp/file
but the problem with that is that it appends the template to the temp
file (leaving the original contents) and it also asks me to press
enter afterwards:
"/home/wiz/template: X lines, Y characters
Press Enter to continue:"
I thought I could improve upon it by deleting the contents first with
a 'd' command. From the error message I found out that I need to use
ex(1) instead of vi(1) commands. Trying this out I found that
echo b > b
vi -c 'd 1' b
gets me into a very weird state in the editor: The cursor is in the
middle of the screen, every line starts with "~" except the one below
the cursor, at the bottom it says "b: modified: line 0" and the first
insert command fails. The second one works.
So this looks like a bug to me.
My question remains: is there a way to set off two commands with vi
-c? If yes, how? I didn't find a separator that works yet.
If not, any other ideas how to get what I want?
Thanks,
Thomas
For commit scripting purposes, I'd like to prefill a temporary file
(which I can't influence directly) with the contents of another file.
Using vi, I'm so far using
EDITOR="vi -c 'r /home/wiz/template'"
which then will expand to
vi -c 'r /home/wiz/template' /tmp/file
but the problem with that is that it appends the template to the temp
file (leaving the original contents) and it also asks me to press
enter afterwards:
"/home/wiz/template: X lines, Y characters
Press Enter to continue:"
I thought I could improve upon it by deleting the contents first with
a 'd' command. From the error message I found out that I need to use
ex(1) instead of vi(1) commands. Trying this out I found that
echo b > b
vi -c 'd 1' b
gets me into a very weird state in the editor: The cursor is in the
middle of the screen, every line starts with "~" except the one below
the cursor, at the bottom it says "b: modified: line 0" and the first
insert command fails. The second one works.
So this looks like a bug to me.
My question remains: is there a way to set off two commands with vi
-c? If yes, how? I didn't find a separator that works yet.
If not, any other ideas how to get what I want?
Thanks,
Thomas