使用vim外部命令调用bash函数 [英] Call bash function using vim external command

查看:88
本文介绍了使用vim外部命令调用bash函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用vim的:!外部命令功能一直存在,通常将%作为shell命令的参数.例如:

I use vim's :! external command function all the time, usually providing % as an argument to the shell command. For example :

:!psql -f %

在我使用的.bashrc中,我还有很多bash shell函数.例如:

I also have a lot of bash shell functions in my .bashrc that I use. For example:

psql-h1 () 
{ 
    /usr/bin/psql -hh1 -d mydb "$@"
}

这些bash函数无法从:!获得!在vim中.有没有办法使它们可用?

These bash functions aren't available from :! inside of vim. Is there a way to make them available?

推荐答案

导出函数.那就是:

psql-h1() { /usr/bin/psql -hh1 -d mydb "$@"; }

export -f psql-h1  ### <-- THIS RIGHT HERE

这将使它们可供作为子进程运行的bash的任何副本使用,即使它是非交互式外壳,因此也不会读取.bashrc .

This will make them available to any copy of bash run as a child process, even if it's a noninteractive shell and so doesn't read .bashrc.

这篇关于使用vim外部命令调用bash函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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