如何在多行编辑的末尾添加不同的数字? [英] how to add different number at end of multi line edit?

查看:126
本文介绍了如何在多行编辑的末尾添加不同的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找不到解决方法,也许甚至不可能?

Having trouble finding a way to do this, maybe it is not even possible?

对于我来说,为了测试if语句/用户交互的流程,请在我们的代码中临时添加40行console.log('trigger-fired-1');.

In my case, for testing flow of if-statements/user-interaction, am temporarily adding 40 lines of console.log('trigger-fired-1'); throughout our code.

但是,要区分它们,每个数字都希望以不同的数字结尾,因此在这种情况下,数字从1到40是这样的:

However, to tell them apart would like each to end with a different number, so in this case, numbers one to forty like so:

在屏幕记录的gif文件中,要复制我想要的内容,我所做的只是复制/粘贴数字1到9.我真正想要的是在最后生成这些数字的快捷键,这样我就省去了键入每个唯一数字的步骤.

In the screen recorded gif, to replicate what I am going for, all I did was copy/paste the numbers one to nine. What I really would like is a shortcut key to generate those numbers at the end for me to eliminate that step of typing out each unique number.

主要是使用Visual Studio代码或Sublime Text进行编码,在某些情况下,快捷方式是相似的,或者至少具有相同的支持,但是对不同的快捷键.

Am primarily coding in Visual Studio Code or Sublime Text, and in some cases shortcuts are similar, or at least have same support but for different shortcut keys.

推荐答案

对于Sublime Text,此问题的解决方案是内部Arithmetic命令. VS Code中可能提供或可能不提供类似的东西(可能带有某种扩展名),但是我对它的把握还不够确定.

For Sublime Text, the solution to this problem is the internal Arithmetic command. Something similar may or may not be available in VS Code (possibly with an extension of some sort) but I'm not familiar enough with it to say for sure.

此命令允许您提供某种表达式,以应用于所有光标位置和/或选定的文本.

This command allows you to provide an expression of some sort to apply to all of the cursor locations and/or selected text.

通过演示,这是您上面概述的示例:

By way of demonstration, here's the example you outlined above:

您提供的表达式会在当时针对缓冲区中的每个选择/插入符号进行一次评估,并且表达式的结果会插入到缓冲区中(或者在选择文本的情况下,它将替换选择).还要注意,当您从输入面板调用此命令时(如在屏幕记录中一样),该面板会向您显示表达式输出的预览.

The expression you provide is evaluated once for every selection/caret in the buffer at the time, and the result of the expression is inserted into the buffer (or in the case of selected text, it replaces the selection). Note also that when you invoke this command from the input panel (as in the screen recording) the panel shows you a preview of what the expression output is going to be.

特殊变量i引用选择编号;选择项的编号从0开始,因此表达式i + 1具有插入选择号从1开始而不是0的作用.

The special variable i references the selection number; selections are numbered starting at 0, so the expression i + 1 has the effect of inserting the selection numbers starting at 1 instead of 0.

特殊变量x而是引用特定选择中的文本.这样,您就可以选择一些文本,然后根据您的表达式进行转换.一个示例是在上面的示例之后立即使用x * 2(确保所有选择仍然存在并包装数字)将所有内容翻倍.

The special variable x refers to the text in a particular selection instead. That allows you to select some text and then transform it based on your expression. An example would be to use x * 2 immediately after the above example (make sure all of the selections are still present and wrapping the numbers) to double everything.

如果愿意,可以一次使用两个变量,也可以同时使用Python math库中的任何变量,例如,如果需要一些真正深奥的日志,例如math.sqrt(i).

You can use both variables at once if you like, as well as anything in the Python math library, for example math.sqrt(i) if you want some really esoteric logs.

上面的示例显示了从命令面板中交互选择的命令,其中表达式自动默认为您想要的示例(i + 1).

The example above shows the command being selected from the command palette interactively, where the expression automatically defaults to the one that you want for your example (i + 1).

如果要将其作为键绑定,则可以将键绑定到arithmetic命令并直接提供表达式.例如:

If you want to have this as a key binding, you can bind a key to the arithmetic command and provide the expression directly. For example:

{
    "keys": ["super+a"],
    "command": "arithmetic",
    "args": {
        "expr": "i+1"
    },
},

这篇关于如何在多行编辑的末尾添加不同的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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