如何在 vim shell 命令中使用 .bashrc 别名?(:!...) [英] How to make .bashrc aliases available within a vim shell command? (:!...)

查看:57
本文介绍了如何在 vim shell 命令中使用 .bashrc 别名?(:!...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

To make the setting permanent, add set set shellcmdflag=-ic to the end of your .vimrc file.

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

Use a bang (!) before sending a command to shell. For example: :! cd folder/.

这篇关于如何在 vim shell 命令中使用 .bashrc 别名?(:!...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆