You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Notepad++中为多行批量应用自定义宏?

解决多行末尾批量添加内容的宏失效问题

问题根源

你当前的宏仅针对单个光标位置执行操作,没有遍历垂直选中的多光标,所以只有第一行生效。

解决方案

方案1:修改宏逻辑(适配多光标)

将宏调整为遍历所有选中行的行尾执行插入操作,以下是主流编辑器的示例逻辑:

  • VS Code(需安装Macro扩展):
    const editor = vscode.window.activeTextEditor;
    if (editor) {
        const document = editor.document;
        editor.edit(editBuilder => {
            editor.selections.forEach(sel => {
                const line = document.lineAt(sel.end.line);
                editBuilder.insert(line.range.end, ' - updated');
            });
        });
    }
    
  • EmEditor:
    在宏中添加循环遍历选中行的逻辑,比如:
    document.selections.forEach(function(sel) {
        document.selection.SetActivePoint(eePosLogical, sel.EndX, sel.EndY);
        document.selection.Text = ' - updated';
    });
    

方案2:用编辑器原生功能替代宏(更便捷)

  1. 多光标批量输入:
    按住Alt(Windows/Linux)或Option(Mac),拖动鼠标选中所有行的末尾位置(形成多光标),直接输入 - updated,所有光标位置会同步插入内容。
  2. 正则替换一键完成:
    打开替换面板(Ctrl+H/Cmd+H),开启正则模式:
    • 查找框输入:$(匹配行尾)
    • 替换框输入: - updated
    • 点击「全部替换」,即可给所有行末尾批量添加内容。

内容的提问来源于stack exchange,提问作者Shu Pesmerga

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 11:55:46