TransWikia.com

PATH order different in vim terminal window

Vi and Vim Asked by froxset on August 31, 2021

I have anaconda set up with a few different environments. When I switch environments and open vim 8.2 and type :term to launch a terminal window and type echo $PATH, $PATH does not match what is shown in a terminal outside of vim. If instead just type :!echo $PATH, it is correct

getting path from the terminal outside of vim:

(tensorflow_p36) ubuntu@ip-172-31-50-75:~$ echo $PATH
/home/ubuntu/anaconda3/envs/tensorflow_p36/bin:/home/ubuntu/anaconda3/bin:/home/ubuntu/anaconda3/condabin:/home/ubuntu/anaconda3/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/home/ubuntu/.dl_binaries/bin:/usr/local/mpi/bin:/opt/aws/neuron/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/opt/amazon/openmpi/bin:/opt/amazon/efa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

getting path using :! echo $PATH from vim command mode (matches $PATH above):

/home/ubuntu/anaconda3/envs/tensorflow_p36/bin:/home/ubuntu/anaconda3/bin:/home/ubuntu/anaconda3/condabin:/home/ubuntu/anaconda3/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/home/ubuntu/.dl_binaries/bin:/usr/local/mpi/bin:/opt/aws/neuron/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/opt/amazon/openmpi/bin:/opt/amazon/efa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Press ENTER or type command to continue

Opening a terminal window within vim and checking $PATH (first 11 directories are duplicates that appear later in $PATH):

(tensorflow_p36) ubuntu@ip-172-31-50-75:~$ echo $PATH                                                                                                                                          
/home/ubuntu/anaconda3/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/home/ubuntu/.dl_binaries/bin:/usr/local/mpi/bin:/opt/aws/neuron/bin:/home/ubuntu/anaconda3/envs/tensorflow_p36/bin:/home/ubuntu/anaconda3/bin:/home/ubuntu/anaconda3/condabin:/home/ubuntu/anaconda3/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/home/ubuntu/.dl_binaries/bin:/usr/local/mpi/bin:/opt/aws/neuron/bin:/usr/local/cuda/bin:/usr/local/bin:/opt/aws/bin:/usr/local/mpi/bin:/opt/amazon/openmpi/bin:/opt/amazon/efa/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Trying to understand why $PATH within a vim terminal window has additional directories prepended…

One Answer

I don't know the "anaconda setup", but assume it is included in your shells configuration files (like .bashrc). It seems to manipulate the PATH environment variable.

When you open a terminal from within Vim a second instance of the shell is started, causing a manipulation of the PATH that was already manipulated. Hence the different value of PATH.

If this behavior is a problem, you can change your shell configuration to not repeat the anaconda stuff if it was already done.

Correct answer by Ralf on August 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP