我在 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/