是否可以有一个考虑我输入长度的片段? [英] Is it possible to have a snippet that considers the length of my input?

查看:22
本文介绍了是否可以有一个考虑我输入长度的片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为评论定义一个片段,例如

//************//* foo A1 *//************

在我输入 foo A1 的地方,它会创建一个带有 (6+ len(${1}) 星号等的行 - 是否可行,如果可行,如何操作?

解决方案

虽然我是

I would like to define a snippet for comments like

//************
//*  foo A1  *
//************

where I enter foo A1 and it would create a line with (6+ len(${1}) asterisks etc. - is that doable and if so, how?

解决方案

While I am a big proponent of HyperSnips (see

[VSCODE]: Is there a way to insert N times the same characters,

VS Code: how to make a python snippet that after string or expression hitting tab will transform it and

VSCode Advanced Custom Snippets for how to use it),

it is instructive to see how to do this with just the built-in snippet functionality in vscode. Here is a snippet that does what you want:

"Custom Comment": {
    "prefix": ["cc2"],    // whatever trigger you want, then tab, write your info and tab again
    "body": [
        "//***${1/./*/g}***",
        "//*  $1  *",
        "//***${1/./*/g}***"
    ]
},

That just adds 3 asterisks to the beginning and 3 to the end of your added comment, each character of which is replaced by an asterisk as well.

这篇关于是否可以有一个考虑我输入长度的片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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