如何在Vim中发送转义序列? [英] How to send escape sequences from within Vim?

查看:106
本文介绍了如何在Vim中发送转义序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,最近苹果公司已经支持在终端的状态栏中显示工作目录和文件。必须发送(设置当前文件)的转义序列是:

So recently Apple have included support for displaying the working directory and file in the status bar of Terminal. The escape sequence that must be sent (to set the current file) is this:

ESC ] 6 ; Pt BEL

其中 Pt file:// 网址指向当前正在编辑的文件。因此,我想我可以让Vim以转义序列的形式发送此命令,但是我有点麻烦。到目前为止,我的信息是:

where Pt is a file:// url pointing to the file currently being edited. So I figured I could get Vim to send this command as an escape sequence, but I'm having a bit of trouble. I have this so far:

au BufNewFile,BufReadPost,BufFilePost,BufWritePost * echo <escape sequence>

但是我有一种感觉,它不会像那样工作。另外,我不知道如何以 file:// 网址获取当前文件,尽管我怀疑netrw可能会帮助我。有任何想法吗?

but I have a feeling that it won't quite work like that. Also, I have no idea how to get the current file as a file:// url, although I suspect netrw might be able to help me. Any ideas?

到目前为止,我有:

au BufNewFile,BufReadPost,BufFilePost * echo printf('\e]6;file://%s%s\a', $HOSTNAME, expand('%:p'))

但它仍然无法正常工作- $ HOSTNAME 没有扩大。任何人都对如何使其扩展有任何提示?

but it still isn't working - $HOSTNAME isn't getting expanded. Anyone have any tips on how to make this expand?

确定,所以我做了对报价进行了一些更改并导出了 $ HOSTNAME ,现在可以正常打印了。但是,vim并非像字面上那样呼出转义序列,而是像 ^ [那样打印它们,这使它们毫无用处!所以这是我真正的问题:您如何使vim将字面量转义序列发送到shell?

OK, so I've made some changes to the quotes and exported $HOSTNAME, and now this is printing out fine. But instead of literally echoing the escape sequences, vim is printing them like ^[, which makes them useless! And so here comes my real question: how do you make vim send literal escape sequences to the shell?

最终代码如下:

set title
set t_ts=^[]6;
set t_fs=^G
auto BufEnter * let &titlestring = "file://" . hostname() . expand("%:p")


推荐答案

您可以使用vim中的!echo -ne< ESCAPE SEQUENCE> 。为了将其与包含变量的标题字符串一起使用,可以在 execute 前面加上前缀。

You can use !echo -ne <ESCAPE SEQUENCE> within vim. In order to use it with your title string which contains variables, execute could be prefixed.

execute "silent !echo -ne " . EXPRESSION

但是说实话,没有必要使用自己的命令。相反,您可以按照此处中的说明操作这两个变量。

But honestly it is not necessary to roll your own command. Instead, you can manipulate these two varialbes as explained here.


如果终端
允许通过发送字符串设置标题,则使用't_ts'和't_fs'选项设置窗口标题。它们分别在
标题字符串之前和之后发送。类似的 t_IS和 t_IE用于设置
图标文字。这些是Unix termcap的Vim内部扩展,因此无法从外部termcap获得
。但是,内置termcap
包含适用于xterm和iris-ansi的条目,因此您无需在此处设置

The 't_ts' and 't_fs' options are used to set the window title if the terminal allows title setting via sending strings. They are sent before and after the title string, respectively. Similar 't_IS' and 't_IE' are used to set the icon text. These are Vim-internal extensions of the Unix termcap, so they cannot be obtained from an external termcap. However, the builtin termcap contains suitable entries for xterm and iris-ansi, so you don't need to set them here.

这篇关于如何在Vim中发送转义序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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