在我的自定义代码段中使用TM_SELECTED_TEXT [英] Using TM_SELECTED_TEXT in my custom snippets

查看:163
本文介绍了在我的自定义代码段中使用TM_SELECTED_TEXT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,随着VSCode的2016年11月版(1.8版)片段变量的支持,特别是TM_SELECTED_TEXT。

With the November 2016 (version 1.8) release of VSCode Snippet Variables are now supported, specifically TM_SELECTED_TEXT.

这让我很高兴,因为我在Sublime Text和TextMate中都大量使用了它们。

This makes me happy as I have used these heavily in both Sublime Text and TextMate.

I无法弄清楚如何使其在VSCode中工作。我创建了它们用作示例的代码段:

I can't figure out how to get it to work in VSCode. I've created the snippet they use as an example:

"in quotes": {
    "prefix": "inq",
    "body": "'${TM_SELECTED_TEXT:${1:type_here}}'"
}

然后输入一些文本,突出显示它,这就是事情开始的地方。

I then enter some text, highlight it and that's where things start to break.

想法是突出显示一些文本,运行代码段,然后将 $ {TM_SELECTED_TEXT:$ {1:type_here}} 替换为突出显示的文本。我遇到的问题是要运行该代码段,您需要输入前缀值(在本例中为 inq )来运行该代码段

The idea is highlight some text, run the snippet and then ${TM_SELECTED_TEXT:${1:type_here}} is replaced with the highlighted text. The problem I'm having is that to run the snippet you need to type the prefix value (in this case inq) to run the snippet which over-writes your highlighted text which messes everything up.

在Sublime / Textmate中,我通过键盘组合启动了代码片段,使我的文本突出显示。

In Sublime/Textmate I launched the snippet from a keyboard combination which left my text highlighted.

在VSCode中,是否可以按原样进行此工作或从Sublime中可用的组合键启动摘要?

Is there a way, in VSCode, to either make this work as is or launch the snippet from a key combination like was available in Sublime?

推荐答案

突出显示单词,按 F1 并运行命令插入代码段,然后在列表中选择您的代码段。

With the word highlighted, press F1 and run the command "Insert Snippet", then select your snippet on the list.

此外,您还可以通过以下操作来编辑键盘绑定:文件> 首选项> 键盘快捷键,并为 editor.action.showSnippets命令,如下所示:

Also you can edit your keybindings by going to File>Preferences>Keyboard Shortcuts and add some shortcut to the "editor.action.showSnippets" command, like this:

{
    "key": "ctrl+alt+s",
    "command": "editor.action.showSnippets",
    "when": "editorTextFocus"
}

这篇关于在我的自定义代码段中使用TM_SELECTED_TEXT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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