Use --cmd instead of -c. It will take effect before the buffer is loaded.
> 2. I cannot prepend /tmp/new-note to "db". If I do this:
> vim -c 'set key=jjj' -c 'r !cat /tmp/new-note' db
> the contents of /tmp/new-note end up getting inserted after the 1st
> line of the original "db".
>
> Basically, I don't know how to open a new line (the 'O' command)
> before the first line of a file via a script!
Use :0r instead of :r.
See :help :r | /:0r
~Matt
When I use
vim --cmd 'set key=foo' db
it doesn't prompt me for the key. Are you saying that you see
something different?
~Matt
Combine the two. Something like
vim --cmd 'set key=foo' -c "0r ! cat /tmp/new-note" db
probably.
The rendering you are seeing is indeed odd, but I don't have any ideas
about that quickly, and it's a side issue, so I will leave it for now!
Ben.
The order of the given options matters.
Consider this:
this will echo "1" while opening a vim instance,
vim -c "let g:var = 1" -c "echo g:var"
but this will complain for an undefined variable,
vim -c "echo g:var" -c "let g:var = 1"
but if you do to that same instance,
:echo g:var
it will echo "1"
So you already have the answer, just concatenate it (it should work):
vim --cmd 'set key=foo' -c "0r !cat /tmp/new-note" db
Regards,
Ag.
So the following command should work (no matter of the order) because
"--cmd"'s have priority (read more in :help --cmd):
vim -c "echo g:var" --cmd "let g:var = 1"
> Consider this:
>
> this will echo "1" while opening a vim instance,
>
> vim -c "let g:var = 1" -c "echo g:var"
>
> but this will complain for an undefined variable,
>
> vim -c "echo g:var" -c "let g:var = 1"
>
> but if you do to that same instance,
>
> :echo g:var
>
> it will echo "1"
>
Regards,
Ag.