David542
David542

Reputation: 110163

Set the vim path in bash

I am trying to do the following in bash to modify my .vimrc:

# *VIM,TMUX-related*
if [(which vim) = '/usr/local/bin/vim'] then
    VIM="/usr/local/bin/vim"
else
    VIM="/usr/bin/vim"
fi
export EDITOR="$VIM"

What would be the proper syntax to do this conditional?

Upvotes: 0

Views: 278

Answers (3)

Javad Rezaei
Javad Rezaei

Reputation: 1110

[["$(which vim)" = "/usr/local/bin/vim"]] && export EDITOR="/usr/local/bin/vim"

will do the trick if you insist on using conditional statement to make sure that vim path exists.

Upvotes: 0

justfortherec
justfortherec

Reputation: 1650

Would it also work for you to directly assign the output of which vim? This seems to be the endresult of this snippet:

export EDITOR="$(which vim)"

Upvotes: 3

Barmar
Barmar

Reputation: 781004

The first line should be:

if [ "$(which vim)" = '/usr/local/bin/vim' ] then

Spaces are needed around [ and ], and you need to use $(...) to substitute the output of a command into the command line. You should also put it in quotes in case it returns an empty string or a string containing whitespace.

Upvotes: 2

Related Questions