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

查看:975
本文介绍了如何为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 ++中的宏只是一堆编码操作:您开始记录,在缓冲区上操作,也许激活菜单,停止记录然后播放宏.
经过调查,我发现它们已保存在宏"部分的"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 ++本身(可能正在激活菜单项). br> 我认为它不会在对话框中记录操作(例如搜索/替换).

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脚本功能(或似乎可以用Python编写的程序员记事本)的SciTE的优势...:-)

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

好像我从此线程获得了上面的宏或类似的地方... :-)我想第一行是不必要的(副作用或记录),但无论如何它们都是宏代码的好例子.

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天全站免登陆