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,763 times
7
Jens
- 65,924
- 14
- 115
- 171
Frank Cheng
- 5,722
- 8
- 49
- 76
-
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
1 Answers
19
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.