Discussion:
vi -c
Thomas Klausner
2014-04-27 15:40:32 UTC
Permalink
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
Alan Barrett
2014-04-27 16:30:37 UTC
Permalink
Post by Thomas Klausner
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.
I don't know.
Post by Thomas Klausner
If not, any other ideas how to get what I want?
vi -c 'source commandfile', where commandfile contains all the commands
you want.

--apb (Alan Barrett)
Thomas Klausner
2014-04-27 16:36:50 UTC
Permalink
Post by Alan Barrett
Post by Thomas Klausner
If not, any other ideas how to get what I want?
vi -c 'source commandfile', where commandfile contains all the commands
you want.
Thank you, that does indeed what I want.
Thomas
Rhialto
2014-04-27 17:40:15 UTC
Permalink
Post by Alan Barrett
Post by Thomas Klausner
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.
I don't know.
The separator is | (vertical bar). Not so intuitive...

For reading a new file in front of the existing text, instead of after
the current line, use "0read filename" instead of "read filename".
The 0 is the line number.
Post by Alan Barrett
Post by Thomas Klausner
If not, any other ideas how to get what I want?
vi -c 'source commandfile', where commandfile contains all the commands
you want.
If you need to do many or long commands, that is certainly a better
option. And maybe i and a commands would even work.
Post by Alan Barrett
--apb (Alan Barrett)
-Olaf.
--
___ Olaf 'Rhialto' Seibert -- The Doctor: No, 'eureka' is Greek for
\X/ rhialto/at/xs4all.nl -- 'this bath is too hot.'
Continue reading on narkive:
Loading...