从 Vim 执行 Bash 中的当前行 [英] Execute current line in Bash from Vim

查看:30
本文介绍了从 Vim 执行 Bash 中的当前行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题类似于Vim:执行当前文件?,但我只想执行当前行而不是执行当前文件.

This question is similar to Vim: execute current file?, but instead of executing the current file I want to execute only the current line.

这可能吗?

理想情况下,我正在寻找可能对外壳产生副作用的解决方案.

Ideally, I am looking for solutions which can have side effects in the outer shell.

例如,假设我有以下行:

For example, suppose I have the following line:

alias foo=bar

在 Vim 中运行命令后,如果我用 :sh 启动 shell,别名 foo 可用,但如果我退出 vim> 使用 :q,则别名不再可用.

After running the command in Vim, if I start a shell with :sh, the alias foo is available, but if I quit vim using :q, then the alias is no longer available.

推荐答案

当然,您可以将当前文件的任何内容写入"到 另一个程序的标准输入:

Sure thing, you can 'write' any content of the current file into the standard input of another program:

:.w !bash

这里的.(w之前的部分)指的是你正在写的行的范围,而.只是当前行.然后使用 !bash 将这些行写入 Bash.

Here . (the part before w) refers to the range of lines you are writing, and . is only the current line. Then you use !bash to write those lines to Bash.

这篇关于从 Vim 执行 Bash 中的当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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