Vim 在交互模式下无法识别别名? [英] Vim not recognizing aliases when in interactive mode?
问题描述
与这个相同的问题,但是那里的解决方案不起作用.
Same question as this, however the solution there didn't work.
我在 ~/.vimrc 中设置了这些变量:
I set these variables in my ~/.vimrc:
set shellcmdflag=-ic
set shell=/bin/bash -i
我的 ~/.bash_aliases 中有一个别名:
and I have an alias in my ~/.bash_aliases:
rgr() { if [ ! -z "$2" ]; then grep -rI --exclude=*.svn* "$1" * --include=$2 ; else grep -rI --exclude=*svn* "$1" * ; fi ; }
从命令行执行时有效,但是当我尝试使用 :!rgr test
从 Vim 调用它时,我收到一条错误消息并且 Vim 退出:
which works when executed from the command line, but when I try to call it from Vim with :!rgr test
, I get an error message and Vim exits:
bash: rgr: command not found
[4]+ Stopped vi ~/somefile
如果我禁用交互模式,我只会收到找不到命令"消息,而 Vim 不会退出.
If I disable the interactive mode, I just get the "command not found" message and Vim doesn't exit.
我怎样才能让 Vim 识别我的别名?我已经在 OS X 和 Ubuntu 上重现了这种行为.
How can I get Vim to recognize my aliases? I've reproduced this behavior on both OS X and Ubuntu.
推荐答案
我通过 bash
的手册页实现了这个功能:
I got this to work, via the man page for bash
:
set shell=/bin/bash --rcfile ~/.bash_profile
类似地,--init-file
也能工作.
注意 -i
不是必须的,虽然它可以添加到命令中:
Note that -i
is not necessary, though it can be added to the command:
set shell=/bin/bash --rcfile ~/.bash_profile -i
示例:
~/.bash_profile
包含
source ~/.bash_aliases
~/.bash_aliases
包含
alias rdc="open -a "Remote Desktop Connection""
~/.vimrc
包含
set shell=/bin/bash --rcfile ~/.bash_profile
map ,r :!rdc &<cr>
这篇关于Vim 在交互模式下无法识别别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!