Why doesn't my vim know my alias?

2020-03-01 20:33发布

问题:

I have used "alias ruby=ruby1.9.1", so I can execute my ruby with this:

ruby 123.rb

or

ruby1.9.1 123.rb

But in my vim, I use :!ruby and get /bin/bash: ruby: command not found.

I must use :!ruby1.9.1

How does alias work? Why vim doesn't know it?

回答1:

When Vim starts a process it makes a system call. It has only inherited the environment variables from your shell if you started it from the shell. But it won't know your bash aliases.

Bash aliases are only a convenience when you enter a command line in the Bash shell. They are expanded by Bash only.

If you want real aliases put symlinks in a private hidden folder, and add that folder to your PATH, or use the alternatives facility.



回答2:

You can try

:set shellcmdflag+=i

to call bass as "interactive" although that does give an annoying message for every shell command executed.



回答3:

Aliases (unlike environment variables) are not inherited by subshells. So if you want an alias always available, you need to set it in your .bashrc file, so every instance of the shell will get it on startup



标签: vim alias