重复的行以升序编号

时间:2019-04-01 15:49:04

标签: visual-studio-code

我正在使用Visual Studio Code,并且一直在重复输入这样的代码:

fmt.Println("Result of test 1:", test1Val/total)
fmt.Println("Result of test 2:", test2Val/total)
fmt.Println("Result of test 3:", test3Val/total)
fmt.Println("Result of test 4:", test4Val/total)
...

看到数字按升序排列,是否有办法在递增其中的数字的同时重复一行代码? (有点像在Excel中向下拖动单元格)

编辑:我正在寻找具有不同值的重复行的VScode函数,该代码仅是示例。

2 个答案:

答案 0 :(得分:0)

代码生成不能解决您的问题。

与此类似的结构是:

testResults := []int{1, 42, 666}
total := 777
for t, result := range testResults {
    fmt.Printf("Result of test %v: %v\n", t, float64(result)/float64(total))
}

答案 1 :(得分:0)

不管代码生成或数组如何,如果您仍想编写类似的代码或文本,并寻找插入数字递增或递减序列的某种方式,则可以使用vs-code-input-sequence扩展名和光标来操纵和配置插入序列的方式。

尽管它并不是提高代码效率的最佳方法,但它仍然是文档和其他文本编辑情况的很好的工具。它使用输入面板(键盘快捷键)插入语法,例如开始,运算符,步骤,数字和基数。

https://marketplace.visualstudio.com/items?itemName=tomoki1207.vscode-input-sequence

扩展信用是tomoki1207