使用“!"运行命令时,如何使vim 使用与我的登录shell 相同的环境? [英] How to make vim use the same environment as my login shell when running commands with "!"?

查看:17
本文介绍了使用“!"运行命令时,如何使vim 使用与我的登录shell 相同的环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 !ls 来执行 bash 命令.但是在我在 ~/.profile 文件中配置了类似 source ~/.usr_profile 的东西后,vim 也不会获取这个文件.因此,当我想执行在 usr_profile 中声明的函数时,我必须运行 :!source ~/.usr_profile &&my_command.当我使用它一两次时,没关系.但是经常使用的时候,我的vimrc就变得乱七八糟.
有没有更好的方法来解决这个问题.谢谢

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

推荐答案

将此行添加到您的 ~/.vimrc 应该可以解决您当前的问题:

Adding this line to your ~/.vimrc should solve your immediate problem:

set shell=bash\ -l

当使用 -l (--login) 调用时,bash 会在启动时读取您的 ~/.profile(以及其他文件)并因此,一切都来自那里.

When invoked with -l (--login), bash reads your ~/.profile at startup (among other files) and thus everything sourced from there.

当使用 -i (--interactive) 调用时,bash 会在启动时读取您的 ~/.bashrc(以及其他文件)并因此,一切都来自那里.

When invoked with -i (--interactive), bash reads your ~/.bashrc at startup (among other files) and thus everything sourced from there.

尝试 $ man bash:h shell:h shellcmdflag 了解更多信息.

Try $ man bash or :h shell and :h shellcmdflag for more info.

至于登录和非登录shell的区别,我必须承认我的无知.这个关于 serverfault 的答案 可能会有所帮助,反正很有趣.

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.

这篇关于使用“!"运行命令时,如何使vim 使用与我的登录shell 相同的环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆