E.g., it I do:
!echo a
or any other !
, it first prints:
syntax error near unexpected token (
ls() ( /* my alias */ )
and then the actual command.
The problem only happens in GVIM, not in Vim.
Ubuntu 16.10, vim 7.4.1829.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityInstead of adding -i
to shellcmdflags
and reading your entire .bashrc
just for loading aliases, keep your aliases in a separate file, like ~/.bash_aliases
for Ubuntu, and add to your vimrc:
let $BASH_ENV = "~/.bash_aliases"
From the bash manual,
Invoked non-interactively
When Bash is started non-interactively, to run a shell script, for example, it looks for the variable
BASH_ENV
in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. Bash behaves as if the following command were executed:if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the
PATH
variable is not used to search for the filename.
Since Vim still invokes bash non-interactively, bash doesn't enable aliases. You can do so by adding to the file:
shopt -s expand_aliases
This is harmless in an interactive shell, so adding it won't cause problems.
The default bashrc for Ubuntu, contains the following lines at the beginning:
if $TERM_IS_COLOR ...
...
else
alias ls="ls -F"
alias ll="ls -lF"
fi
which I had kept.
Then at some point I added:
shellcmdflag=-ic
with i
to have access to my aliases from vim commands.
But the GVIM shell cannot show colors, and only in that case the default alias
comes before my command, and messes things up.
For now, I will just remove the lines:
alias ls="ls -F"
alias ll="ls -lF"
and see some raw shell color commands from time to time on GVIM.