1

I'm using vim 8.1 on windows. The IT department has set $HOME to a slow network drive. Every time a file gets written to $HOME vim slows down.

I have $VIM/vimrc with the following content.

let $HOME = $USERPROFILE

This used to work, but now netrw still creates files on the network drive.

How do I change $HOME so that no slowdown occurs?

  • 1
    Does :echo $HOME and :echo expand("$HOME") print what you expect? (Just to make sure it is not reset afterwards.) – Ralf Jan 4 at 12:50
  • Yes, it does print what I expect – user20406 Jan 4 at 13:23
3

After you answered the question yourself, the focus shifted. It seems the Question is now "How can I prevent Vim from checking for $HOME/_vimrc?".

Try the following:

  • Create the file $USERPROFILE/vimrc with all your configuration.
  • Create the environment variable VIMINIT with the value source $USERPROFILE/vimrc.

On startup the variable VIMINIT is checked first. If it is set, the value of $VIMINIT is used as an Ex command line.


Update (I know that the questioner is not interested anymore):

You should also check your runtimepath. Most likely it still points to $HOME/vimfiles (on Windows). So you should create the directory $USERPROFILE/vimfiles to store extended configuration and plugins etc.

At the beginning of $USERPROFILE/vimrc you have to fix the runtimepath. I would try it like this:

set runtimepath-=~/vimfiles
set runtimepath^=$USERPROFILE/vimfiles
set runtimepath-=~/vimfiles/after
set runtimepath+=$USERPROFILE/vimfiles/after

After that you should still change $HOME, as others (like netrw) still uses it.

let $HOME=$USERPROFILE

I'm on Linux, so someone should test this on Windows.

  • I did what you said. I put let $HOME = $USERPROFILE and color blue in it. It got blue and echo $HOME echoes home, but vim still starts dog slow until I disconnect the network drive. – user20406 Jan 4 at 14:01
0

You can use the -u option to give an alternate .vimrc file of your choice when starting vim. As stated here, you can also use the $MYVIMRC variable to automate this (this takes precedence over $HOME), which should answer your question.

  • I know the -u option, but that's a hack. The $MYVIMRC gets set to the first config file it finds so that's not an option either. – user20406 Jan 4 at 12:31
  • Ok, and what about HOME=new_address vim ... ? – Charles Gueunet Jan 4 at 13:06
  • What do you exactly mean by that? – user20406 Jan 4 at 13:22
  • Also what did you mean in your answer, that $MYVIMRC takes precedence? The documentation says "The $MYVIMRC environment variable is set to the file that was first found, unless $MYVIMRC was already set and when using VIMINIT." – user20406 Jan 4 at 13:27
  • in bash, if you use HOME=$USERPROFILE vim the environment variable $HOME will be set to the content of $USERPROFILE only for the following command: vim. Ok, the $MYVIMRC only point to a file, it is not used by vim to find the .vimrc. Mea culpa. – Charles Gueunet Jan 4 at 13:33
0

Turns out the culprit was

source $VIMRUNTIME/vimrc_example.vim

in my $HOME/_vimrc. After removing it no files were created anymore.

Never mind. After more testing it didn't work.

Solution

Create a vimrc in $VIM with following content

let $HOME = $USERPROFILE

This however is not a perfect solution.

According to the documentation it first searches $HOME and then $VIM. This means there is a slow access to the network drive to check if there exists a vimrc. This is quite noticeable. To fix that you either have to somehow undo the work of the IT guys or open Vim with -u everywhere. Or just keep Vim open forever.

Or you use an editor with manners that saves its configuration in %appdata% like it's supposed to. I'm out.

Your Answer

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