In comp.editors, Ben <
n...@way.com> wrote:
How do the owners of
way.com feel about your use of their domain?
> I'm trying to assign the command below to the F10 key. Assuming you
> have sudo, the command will allow you to save root owned files, even
> though you opened as a normal user. But I can't seem to get it to work
> correctly.
What isn't working? The command, which looks exceedingly complex for
the task, or getting it mapped to F10, which is what your subject
implies.
> map <F10> execute ':silent w !sudo tee % > /dev/null' . "| :edit!"
The map lhs (left hand side, here "<F10>") should be fine.
This bit is super ugly:
:silent w !sudo tee % > /dev/null
Why use 'tee' if you don't want two copies? Use 'cat'. After you run
that bit, as you have probably noticed, vim suddenly becomes aware that
the file has changed underneath it. Your "| :edit!" seems to be the
attempt to fix that, but it doesn't work, does it? I'm not sure if there
is a way to avoid the "reload file" issue.
If you've got sudo, the best option is "sudo vi file" instead of this
convoluted mess. If I really wanted to do this, I'd just live with
map <F10> :w !sudo cat > %
Elijah
------
would most likely save the file in /tmp then copy it as root