I use !ls
to execute bash command. But after i have configured something like source ~/.usr_profile
in ~/.profile
file, vim won't source this file as well. So when i want to execute a function declared in usr_profile
, i have to run :!source ~/.usr_profile && my_command
. When i using this once or twice, it's ok. But when use it frequently, the my vimrc becomes messy.
Is there any better method to solve this problem.Thanks
Asked
Active
Viewed 2,999 times
8

Jens
- 69,818
- 15
- 125
- 179

Frank Cheng
- 5,928
- 9
- 52
- 80
-
possible duplicate of [How do I get vim's :sh command to source my bashrc?](http://stackoverflow.com/questions/1694599/how-do-i-get-vims-sh-command-to-source-my-bashrc) – nwinkler Sep 01 '15 at 06:42
2 Answers
21
Adding this line to your ~/.vimrc
should solve your immediate problem:
set shell=bash\ -l
When invoked with -l
(--login
), bash reads your ~/.profile
at startup (among other files) and thus everything sourced from there.
When invoked with -i
(--interactive
), bash reads your ~/.bashrc
at startup (among other files) and thus everything sourced from there.
Try $ man bash
or :h shell
and :h shellcmdflag
for more info.
As for the differences between login and non-login shell I must admit my ignorance. This answer on serverfault may help, it's interesting, anyway.
0
Append the following two lines to your .vimrc
.
set shell=/bin/bash " use bash
set shellcmdflag="-ic" " flag passed to the shell to execute "!" and ":!" commands
P.S. It seems that the accepted answer may cause some problems when editing '.bash' files or execute a 'git commit', but I don't know why.

Shuqi Xiao
- 1
- 2