4

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.

8

Instead 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.

| improve this answer | |
1

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.