bash - 如何使 .bashrc 别名在 vim shell 命令中可用? (:! ...)

标签 bash vim alias

我在 mac 上使用 bash,其中一个别名是这样的

alias gitlog='git --no-pager  log -n 20 --pretty=format:%h%x09%an%x09%ad%x09%s --date=short --no-merges'

但是当我这样做的时候

 :! gitlog

我明白了

/bin/bash: gitlog: command not found 

我知道我可以在我的 .gitconfig 中添加这样的别名

[alias]
    co = checkout
    st = status
    ci = commit
    br = branch
    df = diff

但是我不想将我所有的 bash 别名都添加到 .gitconfig。那不是干的。

有没有更好的解决方案?

最佳答案

Bash 不会加载你的 .bashrc 除非它是交互式的。

运行 :set shellcmdflag=-ic 将其设置为与当前 session 交互。

要使设置永久生效,请将 set set shellcmdflag=-ic 添加到 .vimrc 文件的末尾。

在向 shell 发送命令之前使用 bang (!)。例如::! cd 文件夹/.

关于bash - 如何使 .bashrc 别名在 vim shell 命令中可用? (:! ...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4642822/

相关文章:

bash - 在脚本中使用 sed 将文件内容替换为行

Vim 在写入文件时似乎卡住了

c++ - vim 插件 youcompleteme for project using scons and g++ compiler

vim - 键入时自动保存在 VIM 中

.htaccess - joomla htaccess 如何识别特定别名的 get 方法是什么?

regex - 进行各种替换,但只能在字符之前

linux - 测试返回值 : command not found

java - 在 Web 应用程序中为 Tomcat 上下文定义别名

python - 如何为 Python 类中的非函数成员属性创建别名?

bash - 无法在 Docker 容器 ("Operation not permitted"中执行二进制文件)