How to change the path of vim command


Jack Thomson

I have two versions installed on vimmacOS :

  • default version /usr/bin/vim,
  • and MacVim (via Homebrew) /usr/local/bin/vim.

When entered vim, the default program will be invoked. I want to use MacVim every time I type vim. Do you know how? Do they both use the same ~/.vimrcfile?

Christopher

Use aliases.

Aliases are defined in one of your BASH RC files ~/.bashrc. Below, if it /usr/local/bin/vim's a symlink, create an alias called vim.

if [ -h '/usr/local/bin/vim' ]; then
    alias vim='/usr/local/bin/vim'
fi

The same logic can be applied as follows.

[ -h '/usr/local/bin/vim' ] && alias vim='/usr/local/bin/vim'
  • -hTest if the file is a symlink, which might be the case when using Homebrew.
  • -xTest if the file is a regular executable.

( The file is determined to be a link when ls -lthe first letter of its permissions is displayed as the letter l in l rwxr-xr-x .)

It may also be necessary to set several variables that the program uses to invoke the default editor.

EDITOR='/usr/local/bin/vim'
VISUAL='/usr/local/bin/vim'

After adding the definition to your shell's RC file, provide the source of the RC file to use the file or whatever new alias is source ~/.bashrcappropriate for your BASH configuration . command, command -v vimshow aliases are created when their output is as follows.

alias vim=/usr/local/bin/vim

Both versions use the same VIM RC file vim.

The advantage of pointing to a symlink instead of a binary executable is that aliases don't need to be updated on every MacVim upgrade. brew update && brew upgradeFor example, Homebrew will keep the symlinks pointing to the correct binary executables when upgrading using .


The system version /usr/bin/vimshould remain the same. It cannot be removed or changed anyway without disabling System Integrity Protection (SIP). The system version can still be used by typing /usr/bin/vim, however, viminvokes /usr/local/bin/vim.


Modify the path.

Another way to make all software installed through Homebrew available is to modify PATHso that all software installed by Homebrew comes first in Windows PATH. First, you need to know which zshRC file already contains the definition of the path.

cd
grep path .z*

One of the results may include fpath. This is not the correct variable. We are looking for a lowercase variable named path. After inferring the filename to edit, possibly ~/.zshrcor ~/.zprofile, then change the value of the pathvariable . For example, paththe following defines /usr/local/binand /usr/local/sbinfirst defines a script or program in the home directory, and last defines the rest of the system-defined path.

path=(
    /usr/local/{bin,sbin}
    $HOME/bin
    $path
)

The resulting Unix PATHvariables are then defined as follows.

/usr/local/bin:/usr/local/sbin:/Users/$username/bin:/usr/bin:/bin:/usr/sbin:/sbin

In zsh pathand Unix PATHvariables are "bundled" typseset, so as long as it is a file variable sourcethat is modified by editing : , eg. Then look at the variable to see if it has been modified as expected: .pathsource ~/.zprofilePATHecho $PATH


The maintainers of Homebrew packages are very good at figuring out which software is causing a problem with macOS (if it /usr/local/bincame first) /usr/bin. For example, if Homebrew were to install GNU id, the name of the software /usr/local/binwould be to avoid problems in gidBSD .id/usr/bin

Related


How to change the command path

Amarad I have a self-compiled program installed on my computer. Try removing it by deleting all folders and files including binaries located in usr/local/bin/. I reinstalled the program from the Ubuntu stable PPA, so now the binaries are in /usr/bin/. However,

How to change the command path

Amarad I have a self-compiled program installed on my computer. Try removing it by deleting all folders and files including binaries located in usr/local/bin/. I reinstalled the program from the Ubuntu stable PPA, so now the binaries are in /usr/bin/. However,

How to change default editor for sudoedit command to vim?

and I am trying to use sudoeditbut it keeps running the nanoeditor. My preferred editor is vim. How can I set it as default? On the man page, man sudoeditI noticed the following: EDITOR Default editor to use in -e (sudoedit) mode if neither SUDO_EDI

How to change default editor for sudoedit command to vim?

and I am trying to use sudoeditbut it keeps running the nanoeditor. My preferred editor is vim. How can I set it as default? On the man page, man sudoeditI noticed the following: EDITOR Default editor to use in -e (sudoedit) mode if neither SUDO_EDI

How to change default editor for sudoedit command to vim?

and I am trying to use sudoeditbut it keeps running the nanoeditor. My preferred editor is vim. How can I set it as default? On the man page, man sudoeditI noticed the following: EDITOR Default editor to use in -e (sudoedit) mode if neither SUDO_EDI

How to change the default path of command prompt?

User 10993431 When I open it cmd, this is what I see: Microsoft Windows [Version 10.0.17134.523] (c) 2018 Microsoft Corporation. All rights reserved. C:\Users\me> How can I say: Microsoft Windows [Version 10.0.17134.523] (c) 2018 Microsoft Corporation. All r

How to change the default path of command prompt?

User 10993431 When I open it cmd, this is what I see: Microsoft Windows [Version 10.0.17134.523] (c) 2018 Microsoft Corporation. All rights reserved. C:\Users\me> How can I say: Microsoft Windows [Version 10.0.17134.523] (c) 2018 Microsoft Corporation. All r

How to change PATH for Makefile $(shell...) command?

user 541686 when i run export PATH := mypath $(error $(shell echo "$${PATH}")) Nothing seems to PATHchange for my call shell. Why is this happening and how do I actually change the PATHfor shellcall? Florian Weimer Is this GNU make? There's a long-standing GN

How to change PATH for Makefile $(shell...) command?

user 541686 when i run export PATH := mypath $(error $(shell echo "$${PATH}")) Nothing seems to PATHchange for my call shell. Why is this happening and how do I actually change the PATHfor shellcall? Florian Weimer Is this GNU make? There's a long-standing GN

How to run cut command in vim and change current file

Solab How can I run the cut command in vim and change the content of the file being edited. I have tried the following without success. :r ! cut -d ":" -f 1 % > % and some other variants. I want to use cut to edit the currently open file and would like to kno

How to run cut command in vim and change current file

Solab How can I run the cut command in vim and change the content of the file being edited. I have tried the following without success. :r ! cut -d ":" -f 1 % > % and some other variants. I want to use cut to edit the currently open file and would like to kno

How to run cut command in vim and change current file

Solab How can I run the cut command in vim and change the content of the file being edited. I have tried the following without success. :r ! cut -d ":" -f 1 % > % and some other variants. I want to use cut to edit the currently open file and would like to kno

How to run cut command in vim and change current file

Solab How can I run the cut command in vim and change the content of the file being edited. I have tried the following without success. :r ! cut -d ":" -f 1 % > % and some other variants. I want to use cut to edit the currently open file and would like to kno

dot command in Vim, last change?

Tyler Durden The dot command in Vim repeats "last change", but I'm not sure what constitutes "last change". For example, if I type the sequence: A; {ESC} j。 Then, a semicolon is appended to the current line, but I have to type 'j' again. In other words, the do

dot command in Vim, last change?

Tyler Durden The dot command in Vim repeats "last change", but I'm not sure what constitutes "last change". For example, if I type the sequence: A; {ESC} j。 Then, a semicolon is appended to the current line, but I have to type 'j' again. In other words, the do

vim: how to pipe such a command?

Elbana I have a text file. value #value2 value2 #value3 ... I wanted to sort with -f and add two tags before #, so I did :'<,'>norm f#i^I^I |!sort -f But gives me a bad output! I know a workaround, using two separate commands :'<,'>norm f#i^I^I^I :'<,'>!sor

vim: how to pipe such a command?

Elbana I have a text file. value #value2 value2 #value3 ... I wanted to sort with -f and add two tags before #, so I did :'<,'>norm f#i^I^I |!sort -f But gives me a bad output! I know a workaround, using two separate commands :'<,'>norm f#i^I^I^I :'<,'>!sor

vim: how to pipe such a command?

Elbana I have a text file. value #value2 value2 #value3 ... I wanted to sort with -f and add two tags before #, so I did :'<,'>norm f#i^I^I |!sort -f But gives me a bad output! I know a workaround, using two separate commands :'<,'>norm f#i^I^I^I :'<,'>!sor

vim: how to pipe such a command?

Elbana I have a text file. value #value2 value2 #value3 ... I wanted to sort with -f and add two tags before #, so I did :'<,'>norm f#i^I^I |!sort -f But gives me a bad output! I know a workaround, using two separate commands :'<,'>norm f#i^I^I^I :'<,'>!sor

vim: how to pipe such a command?

Elbana I have a text file. value #value2 value2 #value3 ... I wanted to sort with -f and add two tags before #, so I did :'<,'>norm f#i^I^I |!sort -f But gives me a bad output! I know a workaround, using two separate commands :'<,'>norm f#i^I^I^I :'<,'>!sor

Pass file path to shell command in vim

David 542 How would I properly "escape" the following command in vim? :!file=expand('%:r') Basically, I want to do something like: $ file=my_filename This way I can execute subsequent shell commands to quote $file. Currently I get this error: Press ENTER or

zsh fails on path completion when command is vim

User 137998 When I try to autocomplete the file (with vim as argument 0): vim ~/.conf <TAB> show: _arguments:450: _vim_files: function definition file not found _arguments:450: _vim_files: function definition file not found _arguments:450: _vim_files: functio

zsh fails on path completion when command is vim

User 137998 When I try to autocomplete the file (with vim as argument 0): vim ~/.conf <TAB> show: _arguments:450: _vim_files: function definition file not found _arguments:450: _vim_files: function definition file not found _arguments:450: _vim_files: functio

How to add vimrc path to vim

Stainless steel Currently, there are some paths to search for .vimrc files. (can be seen in the :scriptnamescommand ). How to add other paths? Ingo Karkat This 'runtimepath'option specifies the location of the Vim configuration subdirectory (i.e. the containin

How to add vimrc path to vim

Stainless steel Currently, there are some paths to search for .vimrc files. (can be seen in the :scriptnamescommand ). How to add other paths? Ingo Karkat This 'runtimepath'option specifies the location of the Vim configuration subdirectory (i.e. the containin

How to search in vim 'scriptnames' command

Gecko The vim 'scriptnames' command outputs all loaded scripts. The problem is that I can't find any feasible way to filter/search/find it. I'm looking for some scripting without having to go through "eye violence" to do it. Katsura Sato There is no such thing