我想在 10 行vscode編輯器中插入 [11,12,...,20],不知何故我想模擬vscode 編輯器中的iota功能golang,例如假設我們在 vscode 編輯器中有這些行:
line1 xxxxx
line2 xx
line3 xxxxxxxx
.
.
.
line10 xxx
我想使用 vscode 自定義代碼段將 [11,12,...,20] 添加到每一行的末尾!
所需的輸出將是:
line1 xxxxx11
line2 xx12
line3 xxxxxxxx13
.
.
.
line10 xxx20
vscode 提供的代碼片段是否有可能,或者我們應該為此目的開發一個擴展?請注意,theinit value = 11和 thecount=10是用戶定義的,一開始并不知道。
uj5u.com熱心網友回復:
這是一個示例,您可以如何將數字附加到前 10 行的末尾(如果數量較少,則附加到現有行)。
摘自package.json:
"activationEvents": [
"onCommand:stackoverflow-71294699.appendNumbers"
],
"contributes": {
"commands": [
{
"command": "stackoverflow-71294699.appendNumbers",
"title": "Append numbers"
}
]
},
擴展名.ts:
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.commands.registerCommand('stackoverflow-71294699.appendNumbers',
async function () {
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
await editor.edit((editBuilder) => {
for (let i=0; i<10; i ) {
if (i >= editor.document.lineCount) {
break;
}
const line = editor.document.lineAt(i);
editBuilder.insert(
new vscode.Position(i, line.text.length),
"" (10 i)
);
}
});
})
);
}
export function deactivate() {}
uj5u.com熱心網友回復:
您可以使用擴展
所以選擇盡可能多的行。10并用您想要添加到每個匹配項的任何內容替換鍵系結。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/434289.html
