2

I work with lots of different servers and would like to unify my vimrc across them all. I see that vim has the source command, which I'm assuming works similar to bash. In bash, to source a file from a webpage you go

. <(curl -s domain.com)

How can I do this with vim? I'm aware that I can instead apply each vim setting by adding an alias like so:

alias vim="vim +'colorscheme elflord'"

but I'd rather not pass thru all my settings like that. I don't want to have to create a file on the local server I'm on, hence the desire to instead source into the local session. Any ideas would be appreciated!

  • I'm not sure, but maybe you could try this: $ vim -Nu <(curl url) – user9433424 Oct 29 '16 at 7:23
  • Wow, this actually worked. So simple too. I'll accept this as an answer as it fits my requirements if you post! – Egrodo Oct 30 '16 at 3:47
3

From :h -u:

-u {vimrc}  The file {vimrc} is read for initializations.  Most other
        initializations are skipped; see |initialization|.  This can
        be used to start Vim in a special mode, with special
        mappings and settings.  A shell alias can be used to make
        this easy to use.  For example:  
            alias vimc vim -u ~/.c_vimrc !*

So, when you want to start Vim with a custom vimrc, you can use:

$ vim -u {custom_vimrc}

But starting Vim like this will enable the 'compatible' option:

    Using the "-u" argument has the side effect that the
    'compatible' option will be on by default.  This can have
    unexpected effects.  See |'compatible'|.

… which is probably not what you want. To be sure 'compatible' is disabled, you can add the -N argument:

$ vim -Nu {custom_vimrc}

Finally, if your {custom_vimrc} file is not on your local machine but on the web, you can use a process substitution, which appears to be:

a form of redirection where the input or output of a process (some sequence of commands) appear as a temporary file.

One of the possible syntax using process substitution seems to be:

$ shell_command <( <LIST> )

… where <LIST> is a command list.

You could use this to make the output of the shell command curl url appear as a temporary file to vim -Nu. So, maybe you could start Vim from your shell with a command like this:

$ vim -Nu <(curl url)

For example:

$ vim -Nu <(curl https://raw.githubusercontent.com/tpope/vim-sensible/master/plugin/sensible.vim)
2

AFAIK, source don't let you source anything else than a file.

So you can have, simple and dirty:

function! GetAndSource(url)

  execute '!curl ' . a:url . ' -o vimrc.vim'
  source vimrc.vim
  execute '!rm vimrc.vim'

endfunction

command! -nargs=1 GS call GetAndSource(<f-args>)

Will curl the file, source it and remove it afterwards.

Obviously, you can execute each element separately, and it'll work the same.

  • nice, I just tried tested this with a vimrc from rawgit.com - as last I checked - github had ceased providing raw files with correct HTTP headers (i.e. they would only serve the file wrapped in a HTML webpage). But interestingly it seems github have restored their raw file service, e.g. this URL would work with your function raw.githubusercontent.com/thoughtbot/dotfiles/master/vimrc – the_velour_fog Oct 29 '16 at 5:16
  • Would prefer not to create any files, but I'll definitely keep this in mind, thanks!I – Egrodo Oct 30 '16 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.