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。那不是 DRY。

有更好的解决方案吗?

最佳答案

除非是交互式的,否则 Bash 不会加载您的 .bashrc

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

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

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

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

相关文章:

linux - 如何让 GNU screen 读取 .bash_profile/.bash_rc 更改?

vim - 如何在 vim 编辑器中对齐对齐?

vim - 使用病原体和 git 子模块自定义 vim 包

clojure - 是 :refer and :as to be used simultaneously?

java - hibernate :标准。向标准对象添加别名

html - 在每个 unix GREP 结果周围添加 HTML 标签

bash - 通过 bash 脚本以非交互方式配置 s3cmd

vim - vim 中的反向杀戮词?

localhost - 在 IIS Express 中为 Visual Studio 设置本地主机别名

bash - 推荐 - Zsh 与 FishShell。脚本、生产力和 poweruser 本身