VSCode片段触发之前带有文本? [英] VSCode Snippet trigger with text before?

查看:65
本文介绍了VSCode片段触发之前带有文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在VSCode中创建一个显示PHP箭头的代码段.当我按下键²"然后按TAB时,我需要PHP箭头->".

I want to create a snippet in VSCode that display the PHP arrow. When I press the key "²" then TAB I want the PHP arrow "->".

这是我的代码段

"PHP arrow": {
    "prefix": "²",
    "body": "->$0",
    "description": "PHP Arrow ->"
},

当²"字符周围什么都没有,但是当我编写类似的代码时,它会很好地工作

It works fine when there is nothing around the "²" char but when I write some code like

$this²

代码段未触发

我该怎么办?

谢谢你,祝你有美好的一天:)

Thank you and have a nice day :)

PS:²字符在VSCode中为 oem_7

PS: The ² char is oem_7 in VSCode

推荐答案

我不知道您要使用哪些击键来插入上标².但是,如果您尝试将其用作单词结尾的摘要,请尝试进行键盘绑定.

I don't know what keystrokes you are using to insert the superscript ². But if you are trying to use it as a snippet at the end of a word try making a keybinding instead.

VSCode无法知道²是否打算作为单词的一部分.

在您的 keybindings.json 中尝试此操作-不在摘要文件中:

Try this in your keybindings.json - not in a snippet file:

{
  "key": "2",
  "command": "editor.action.insertSnippet",
  "when": "resourceExtname == .php",
  "args": {
    "snippet": "->$0"
  }
}

键入 $ this2 会产生 $ this-> :

很明显,您必须将上面的 2 键替换为您想使用的任何键.现在,您可以将代码段用作单词的一部分或单词的结尾,而无需任何必要的单词边界.

Obviously you will have to replace the 2 key above with whatever you want to use. Now you can use the snippet as part of a word or at the end of a word without any necessary word boundary.

这篇关于VSCode片段触发之前带有文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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