5

I actually have the following situation and thats what working actually:

Imagine you have to work as root on a file but you want ur own .vimrc without calling "-u". So I started the following "plugin":

let g:realuser=system('w | grep $(ps w | grep ' . getpid() . ' | head -n1 | awk "{ print \$2 }") | awk "{ print \$1 }"')
if $USER == 'root'
    let g:vimrc=system('printf /home/%s/.vimrc '. g:realuser)
    if filereadable(g:vimrc)
        exec ":source " . g:vimrc
        finish
    endif
endif

I call it "realuser.vim" and "source" it in the root's .vimrc (/root/.vimrc).

If you login to your server now via SSH or on ubuntu via Gnome, you go "su -" and login as root. Then u change to your working directory and open the file. The script detects, that the real user who logged on to the machine is "yourlogin". Then it checks if in /home/yourlogin/ a file ".vimrc" is existent. So, it is and it loads it.

My problem is, that in /home/yourlogin/.vimrc is the following line:

source ~/.vim/plugin/someplugin.vim

So guess what. The /root/.vimrc loads the /home/yourlogin/.vimrc and therefore checks in /root/.vim/plugin/someplugin.vim which is not existent since it is only in /home/yourlogin/.vim

How can I use relative paths or sth like that to tell vim that the source file is only in /home/yourlogin/.vim/?

4

2 回答 2

11

的相对等价物:source:runtime

source ~/.vim/plugin/someplugin.vim

变成

runtime plugin/someplugin.vim

有了这个,只要您还调整了'runtimepath'选项中的路径,它就应该可以工作。

或者,您也可以更改$HOMEVim 内部的值;这也会影响 的扩展~

:let $HOME = '/home/yourlogin'
于 2013-10-16T11:27:13.797 回答
0

您可能在此过程中学到了很多东西,所以我不会称其为浪费时间,但是……解决实际问题的方法很简单,就是使用sudoedit. 见$ man sudo

此外,如果您需要升级权限以进行扩展编辑会话,您可能应该花一点时间来修改您的设置/工作流程。

于 2013-10-16T11:36:26.640 回答