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