Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
954 views
in Technique[技术] by (71.8m points)

bash - Vim not recognizing aliases when in interactive mode?

Same question as this, however the solution there didn't work.

I set these variables in my ~/.vimrc:

set shellcmdflag=-ic
set shell=/bin/bash -i

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 ; }

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

If I disable the interactive mode, I just get the "command not found" message and Vim doesn't exit.

How can I get Vim to recognize my aliases? I've reproduced this behavior on both OS X and Ubuntu.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want non-interactive shell (as default) but expansion of bash aliases, put your alias definitions in a file, e.g. .bash_aliases and explicitly enable alias expansion in this file:

shopt -s expand_aliases
alias la='ls -la'

Then add this to your .vimrc so the aliases file is actually read each time you run a shell command from within vim:

let $BASH_ENV = "~/.bash_aliases"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...