When I try to call an aliased shell command from vim using :!
it says
bash: l: command not found
shell returned 127
l
is
alias l=ls
(from my .bashrc)
When I try to call an aliased shell command from vim using :!
it says
bash: l: command not found
shell returned 127
l
is
alias l=ls
(from my .bashrc)
Use the vim command :set shellcmdflag=-ic
which tells it to use the -i
argument when starting a shell when executing a :!
command. The -i
argument means interactive (the shell you are commonly using in terminal), and the way it solves the problem is to use the -i
argument, which tells bash to read the .bashrc
with your aliases (and probably .bash_alises
if you have one). But that may not be what you want because this solution leads to weird behaviour, like vim going into the foreground (use 'fg' to recall it).
A better solution is add this line to your .bashrc
(or .bash_aiases
):
shopt -s expand_aliases
Then all aliases, even in non-interactive shells, will be expanded correctly.
Also, add this to your .vimrc
so the aliases file is actually read each time you run a shell command from within vim:
let $BASH_ENV = "~/.bash_aliases"
Original answer: https://stackoverflow.com/a/19819036/6152931
Bash manual (explains the difference between interactive and non-interactive shells).