在交互模式下,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屋!