如何使.bashrc别名在vim shell命令中可用?(:!...) [英] How to make .bashrc aliases available within a vim shell command? (:!...)
问题描述
我在Mac上使用bash,别名之一就是这样
I use bash on mac and one of the aliases is like this
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中添加这样的别名
I know I can add aliases like this in my .gitconfig
[alias]
co = checkout
st = status
ci = commit
br = branch
df = diff
但是,我不想将所有bash别名添加到.gitconfig.那不是DRY.
However I don't want to add all my bash aliases to .gitconfig. That is not DRY.
有更好的解决方案吗?
推荐答案
除非交互式,Bash不会加载您的 .bashrc
.
Bash doesn’t load your .bashrc
unless it’s interactive.
运行:set shellcmdflag = -ic
将其设置为在当前会话中为交互式.
Run :set shellcmdflag=-ic
to set it to interactive for the current session.
要永久保留设置,请在 .vimrc
文件的末尾添加set set shellcmdflag = -ic
.
To make the setting permanent, add set set shellcmdflag=-ic
to the end of your .vimrc
file.
在将命令发送到shell之前,请使用一声(!
).例如: :!cd文件夹/
.
Use a bang (!
) before sending a command to shell. For example: :! cd folder/
.
这篇关于如何使.bashrc别名在vim shell命令中可用?(:!...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!