Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 创建自定义Vim命令以在bash概要文件中运行函数_Linux_Bash_Shell_Vim - Fatal编程技术网

Linux 创建自定义Vim命令以在bash概要文件中运行函数

Linux 创建自定义Vim命令以在bash概要文件中运行函数,linux,bash,shell,vim,Linux,Bash,Shell,Vim,我是否可以创建一个Vim命令来执行bash配置文件中的函数 在我的bash配置文件中,我有一个函数可以通过webdav将文件上传到远程位置。该函数用于完成此操作 我希望能够在Vim中编辑一个文件,通过键入:w+enter,将更新写入该文件,然后运行一个自定义命令,在不关闭该文件的情况下执行my duck.sh函数 这可能吗?下面是我要执行的函数: upload() { if [ -z "$1" ]; then echo "No file or di

我是否可以创建一个Vim命令来执行bash配置文件中的函数

在我的bash配置文件中,我有一个函数可以通过webdav将文件上传到远程位置。该函数用于完成此操作

我希望能够在Vim中编辑一个文件,通过键入
:w+enter
,将更新写入该文件,然后运行一个自定义命令,在不关闭该文件的情况下执行my duck.sh函数

这可能吗?下面是我要执行的函数:

upload() {
        if [ -z "$1" ]; then
                echo "No file or directory submitted"
        else
                DIR=`pwd`
                if [ "$DIR" = "$WEBDAV_LOCAL_DIR" ]; then
                        duck -u $WEBDAV_USERNAME -p $WEBDAV_PASSWORD --upload $WEBDAV_URL/$1 $1 --existing overwrite
                else
                        echo "You must be in the following directory to use this function: $WEBDAV_LOCAL_DIR"
                fi
        fi
}

为了正常工作,需要将该函数传递给当前正在编辑的文件的路径。

您可以使用自动命令进行此操作

autocmd BufWrite .bash_profile silent! !bash -c upload
每次写入名为
.bash\u profile
的文件时,都会运行此操作。您可以删除
!静默
如果不想使输出静默。您可以在以下帮助主题中阅读其中一些命令:

:help :autocmd
:help autocmd-events-abc
:help :silent
:help :!
可能重复的