简体   繁体   English

在intellij中创建宏

[英]creating macros in intellij

I am trying to create a macro that takes a selection of text and runs some find/replace on it using a regex.我正在尝试创建一个宏,该宏需要选择文本并使用正则表达式在其上运行一些查找/替换。 I have recorded this macro in intellij, but when I run it, all I get is the find/replace dialog opened.我已经在 intellij 中记录了这个宏,但是当我运行它时,我得到的只是打开了查找/替换对话框。 No find/replace is executed.不执行查找/替换。

Has anyone had any luck with creating a find/replace macro in intellij?有没有人在 intellij 中创建查找/替换宏很幸运?

I can't get get the macro find/replace to work either but I can give you two things that might solve your problem:我也无法让宏查找/替换工作,但我可以给你两件事可能会解决你的问题:

  1. If it is only a few places/times you need to do it find/replace has memory of earlier replacements (arrow down in search/replace fields).如果它只是几个地方/时间你需要做它查找/替换有早期替换的记忆(搜索/替换字段中的向下箭头)。

  2. Write a plugin (yes seriously it is not hard at all) to do this.编写一个插件(是的,这并不难)来做到这一点。 I was surprised how easy it was, even though the documentation could be improved.我很惊讶它是多么容易,即使文档可以改进。

And a bonus way of doing it, I just thought of:还有一个额外的方法,我只是想到:

  1. Open the file in Emacs record replacing macro (or write an elisp function to do it), this is the way I would have done it until I learned how easy it was to make Idea plugins.在 Emacs 记录替换宏中打开文件(或编写一个 elisp 函数来执行此操作),这是我一直使用的方法,直到我了解到制作 Idea 插件是多么容易。

This appears to be a long-standing bug in IntelliJ.这似乎是 IntelliJ中长期存在的错误 One workaround that worked for me was this:对我有用的一种解决方法是:

  • Install the IdeaVim plugin .安装IdeaVim 插件
  • When recording a macro requiring searching, enable Vim mode (Tools -> Vim Emulation) during the macro, position the cursor using standard Vim measures, disable Vim mode.录制需要搜索的宏时,在宏期间启用 Vim 模式(工具 -> Vim 仿真),使用标准 Vim 度量定位光标,禁用 Vim 模式。

In general, Vim emulation can be really handy for IntelliJ macros.一般来说,Vim 仿真对于 IntelliJ 宏来说真的很方便。

如果一切都失败了,你可以尝试AutoITAutoHotKeyApplescript其他通用宏系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM