How to make vim use the same environment as my login shell when running commands with “!”?

喜你入骨 提交于 2019-12-21 04:48:12

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/9092347/how-to-make-vim-use-the-same-environment-as-my-login-shell-when-running-commands

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!