如何为 Notepad++ 编写宏? [英] How to write macro for Notepad++?

查看:115
本文介绍了如何为 Notepad++ 编写宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 Notepad++ 编写一个宏,它应该分别用 char4、char5、char6 替换 char1、char2、char3.

I would like to write a macro for Notepad++ which should replace char1, char2, char3 with char4, char5, char6, respectively.

推荐答案

Notepad++ 中的宏只是一堆编码操作:您开始录制,操作缓冲区,也许激活菜单,停止录制然后播放宏.
经过调查,我发现它们保存在 Macros 部分的文件 shortcuts.xml 中.例如,我有:

Macros in Notepad++ are just a bunch of encoded operations: you start recording, operate on the buffer, perhaps activating menus, stop recording then play the macro.
After investigation, I found out they are saved in the file shortcuts.xml in the Macros section. For example, I have there:

<Macro name="Trim Trailing and save" Ctrl="no" Alt="yes" Shift="yes" Key="83">
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="1" message="2170" wParam="0" lParam="0" sParam=" " />
    <Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
    <Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
    <Action type="2" message="0" wParam="42024" lParam="0" sParam="" />
    <Action type="2" message="0" wParam="41006" lParam="0" sParam="" />
</Macro>

我没有查看源代码,但从外观上看,我会说我们有消息发送到 Scintilla(编辑组件,可能类型 0 和 1)和 Notepad++ 本身(可能激活菜单项).
我认为它不会在对话框中记录操作(例如搜索/替换).

I haven't looked at the source, but from the look, I would say we have messages sent to Scintilla (the editing component, perhaps type 0 and 1), and to Notepad++ itself (probably activating menu items).
I don't think it will record actions in dialogs (like search/replace).

查看 Scintilla.iface文件中,我们可以看到 2170 是 ReplaceSel 的代码(即插入字符串是什么都没有选择),2327 是 Tab 命令,Resource Hacker(随便用吧……)显示 42024 是Trim Trailing Space"菜单项目和 41006 是保存".
我猜动作类型 0 用于带有数字参数的 Scintilla 命令,类型 1 用于带有字符串参数的命令,2 用于 Notepad++ 命令.

Looking at Scintilla.iface file, we can see that 2170 is the code of ReplaceSel (ie. insert string is nothing is selected), 2327 is Tab command, and Resource Hacker (just have it handy...) shows that 42024 is "Trim Trailing Space" menu item and 41006 is "Save".
I guess action type 0 is for Scintilla commands with numerical params, type 1 is for commands with string parameter, 2 is for Notepad++ commands.

问题:Scintilla 没有全部替换"命令:客户端的任务是进行迭代,无论是否确认,等等.
另一个问题:似乎类型 1 操作仅限于 1 个字符(我手动编辑,退出 N++ 时它被截断).
我尝试了一些技巧,但我担心这样的任务超出了宏的能力.

Problem: Scintilla doesn't have a "Replace all" command: it is the task of the client to do the iteration, with or without confirmation, etc.
Another problem: it seems type 1 action is limited to 1 char (I edited manually, when exiting N++ it was truncated).
I tried some tricks, but I fear such task is beyond the macro capabilities.

也许这就是具有 Lua 脚本能力的 SciTE(或似乎可以用 Python 编写脚本的程序员记事本)具有优势的地方...... :-)

Maybe that's where SciTE with its Lua scripting ability (or Programmer's Notepad which seems to be scriptable with Python) has an edge... :-)

看起来我从 this thread 获得了上述宏 或类似的地方... :-) 我猜第一行是不必要的(副作用或录音),但无论如何它们都是宏代码的好例子.

Looks like I got the above macro from this thread or a similar place... :-) I guess the first lines are unnecessary (side effect or recording) but they were good examples of macro code anyway.

这篇关于如何为 Notepad++ 编写宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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