3

I installed ubuntu-20.04.3-desktop-amd64.iso on VirtualBox 6.1.28. It is my first foray into virtual machines and Linux.

I installed Vim 8.1 according to this page.

The command :e ~/tmp/tmp.txt opens up /tmp/tmp.txt rather than the expected ~/tmp/tmp.txt. However, :e ~MyUserName/tmp/tmp.txt opens up ~MyUserName/tmp/tmp.txt as expected.

Furthermore, for the :e command, whenever I specify a filepath starting with ~/, (e.g., ~/ or ~/tmp) the vim process is pushed to the background and I am brought to the bash prompt. This happens immediately after I press Return. Issuing %% puts me back into Vim, but I am the wrong folder. For :e ~/, I am editing /, while for :e ~/tmp, I am editing /tmp.

I never saw ~ being ignored before, either on Solaris back in the day, nor in Cygwin in the past 1.5 decades. Cygwin's Vim is no version 8.2.

What can I do to have Netrw recognize ~?

8
  • That typically means the $HOME environment variable is not properly set... What does :echo $HOME tell you inside Vim? Or echo $HOME in your shell?
    – filbranden
    Nov 1 '21 at 23:55
  • Though the "going to background" part is really odd... Does that happen right as you type the ~, or when you press Enter at the end of the command? Can you try to check whether the same happens under vim --clean? Are you connecting to your VirtualBox via SSH or something, or using the VirtualBox console directly? Running a GUI environment such as GNOME on your Ubuntu VM?
    – filbranden
    Nov 1 '21 at 23:58
  • @filbranden: Just before reading your comments, I found that :echo $USERNAME works, but :echo "+".$HOME."+" shows a zero-length string for $HOME. It is not empty if I run vim -u NONE or vim --clean. I am currently trying to track down where $HOME gets clobbered in my ginormous /etc/vim/vimrc. A search for HOME identifies all locations, none of which would clobber $HOME. I'll clarify above exactly when Vim gets put into the background. Nov 2 '21 at 0:28
  • 1
    The problem was the vimscript if has("win32unix") <code for Cygwin> else <code for Windows>. That worked when I only used Cygwin and Windows. Now I I run a Ubuntu VM, and this scenario falls through to code for Windows. I had to change else to elseif !has("unix") to prevent this. Worthwhile posting as an answer, or simply deleting the question? Nov 2 '21 at 0:45
  • I think you can also manually assign the variable in your .vimrc: :let $HOME="/home/user" Nov 2 '21 at 6:07
2

As filbranden commented, the inability to recognize one's home directory ~/ is often due to an improperly set $HOME variable. You can check this with :echo $HOME.

This next part is more specific to my situation. One way that $HOME could be mis-set is if you have conditional vimrc code that customizes it based on the OS that vim is operating in. I had code that sets it differently depending on whether I used Cygwin's Vim or Windows's Vim. I recently moved to Ubuntu, and the vimrc logic wasn't properly coded to recognize this and act accordingly. As coded, the logic caused the Windows code to run, which sets $HOME based on $USERPROFILE. In Ubuntu, $USERPROFILE does not exist. The vimcode resulted in $HOME being an empty string.

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.