搜索并替换为术语列表?

Search and replace with term list?

我想知道是否有一个程序可以使用我想要替换的术语列表而不是一个一个地替换。

例子

À=À
â=â
Â=Â
å=å
Å=Å
ã=ã
Ã=Ã

提前致谢

我使用 UltraEditpowergrep atm

这是我的 umlaut2html-Makro,它执行一些自动文本替换。我想它可以作为灵感 ;-)

// Lessons learned from Mofi ;-)
UltraEdit.ueReOn();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=true;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=false;
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replaceAll=true;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
UltraEdit.activeDocument.findReplace.selectText=false;
UltraEdit.activeDocument.findReplace.regExp=false;
UltraEdit.activeDocument.findReplace.replace("ä","ä");    
UltraEdit.activeDocument.findReplace.replace("ö","ö");    
UltraEdit.activeDocument.findReplace.replace("ü","ü");    
UltraEdit.activeDocument.findReplace.replace("Ä","Ä");    
UltraEdit.activeDocument.findReplace.replace("Ö","Ö");    
UltraEdit.activeDocument.findReplace.replace("Ü","Ü");    
UltraEdit.activeDocument.findReplace.replace("ß","ß");    

将其保存到您喜欢的任何位置的 .js 文件中(MyDocuments\UE-Scripts 可能是一个不错的选择),然后调用脚本 > "Scripts..." 和 "Add",导航到 select 那个 .js 文件。

UltraEdit 有 2 个自动重新格式化任务的功能:macrosscripts.

请参阅 UltraEdit 论坛主题 When to use Scripts over Macros 了解差异的简要概述。

UltraEdit 宏

UltraEdit 宏可以通过简单地记录您在文件上手动执行一次的替换来创建,或者您直接在 Edit/Create 宏 对话框中对其进行编码。

手动创建如下:

  1. UltraEdit 菜单中单击 Macro 菜单项 Edit Macro.
  2. 单击按钮 新建宏
  3. 输入 宏名称 例如 ReplaceEntities.
  4. 取消选中宏 属性 显示该宏的取消对话框
  5. 让宏 属性 如果未找到搜索字符串 则继续检查。
  6. 如果将来需要通过按键快速执行宏,请分配热键或和弦以便通过按键快速执行。
  7. 单击按钮 确定
  8. 回到 Edit/Create 宏 ,现在有新的宏 selected,编辑字段中已经存在 3 行宏命令:
    InsertMode
    ColumnModeOff
    HexOff
  9. 在这 3 个宏命令下面必须为这个重新格式化任务添加下面发布的宏代码行。
  10. 单击按钮 关闭 并确认问题以使用按钮 .
  11. 更新宏

宏就可以使用了

  • 由 hotkey/chord、
  • 分配
  • 宏列表中双击它通过视图-Views/Lists-宏列表打开,以防万一已经可见(停靠或浮动),或
  • 通过使用 宏 - 播放 Any/Multiple 次

此外,宏 - 再玩一次 可以经常使用,具体取决于上次执行的是哪个宏。

除了对话框中已经存在的 3 个标准命令之外,还需要宏代码来替换整个活动文件 HTML 实体,例如:

Top
UltraEditReOn
Find MatchCase "À"
Replace All "À"
Find MatchCase "â"
Replace All "â"
Find MatchCase "Â"
Replace All "Â"
Find MatchCase "å"
Replace All "å"
Find MatchCase "Å"
Replace All "Å"
Find MatchCase "ã"
Replace All "ã"
Find MatchCase "Ã"
Replace All "Ã"

有必要使用 宏 - 全部保存.

将此 UE 宏(不包含或包含其他 UE 宏)保存到宏文件中

为了稍后再次使用此宏(以及存储在同一宏文件中的其他宏),需要使用 宏 - 加载.

加载宏文件

使用宏 - 设置自动加载可以select一个宏文件,以便在 UltraEdit 启动时自动加载,这样这个宏文件中的宏是从一开始就可用,无需显式加载宏文件。

稍后也可以使用 宏 - 删除 Macro/Modify 属性 更改宏属性。不要忘记在对宏代码或其属性进行更改后使用 宏 - 全部保存 将此更改也保存在宏文件中。

UltraEdit 脚本

UltraEdit 脚本使用 JavaScript 核心引擎。 UltraEdit 脚本是一个 ASCII/ANSI 文本文件,其中包含 JavaScript 核心代码以及其他与 UltraEdit 相关的脚本命令。这意味着 UltraEdit 脚本可以像任何其他文本文件一样直接编写,并且不能在对话框中编辑。

与上述宏完全相同的 UltraEdit 脚本为:

if (UltraEdit.document.length > 0)  // Is any file opened?
{
   // Define environment for this script.
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();
   UltraEdit.activeDocument.hexOff();

   // Move caret to top of the active file.
   UltraEdit.activeDocument.top();

   // Define all parameters for several Replace All in entire active file.
   UltraEdit.ueReOn();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=false;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   UltraEdit.activeDocument.findReplace.preserveCase=false;
   UltraEdit.activeDocument.findReplace.replaceAll=true;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
   UltraEdit.activeDocument.findReplace.selectText=false;
   // This property is only available since UE v14.10.
   if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
   {
      UltraEdit.activeDocument.findReplace.searchInColumn=false;
   }

   UltraEdit.activeDocument.findReplace.replace("À","À");
   UltraEdit.activeDocument.findReplace.replace("â","â");
   UltraEdit.activeDocument.findReplace.replace("Â","Â");
   UltraEdit.activeDocument.findReplace.replace("å","å");
   UltraEdit.activeDocument.findReplace.replace("Å","Å");
   UltraEdit.activeDocument.findReplace.replace("ã","ã");
   UltraEdit.activeDocument.findReplace.replace("Ã","Ã");
}

这样的 UltraEdit 脚本应该以 .js 的文件扩展名保存,例如 ReplaceEntities.js.

保存 UE 脚本后,可以通过 Scripting - Scripts 添加到 Script List 并添加简短描述脚本并将 hotkey/chord 分配给脚本以便按键快速执行。

脚本就可以使用了

  • 由 hotkey/chord、
  • 分配
  • 通过在脚本列表中双击它,通过查看-Views/Lists-脚本列表或[=65=打开]Scripting - 脚本列表 在不可见(停靠或浮动)的情况下,或
  • 通过单击菜单中的脚本文件名 脚本

如果 UE 脚本是活动文件并且它被写入 运行 而不是活动文档,则脚本也可以使用 脚本 - 运行 活动脚本 。但是像上面这样的大多数脚本都被写入 运行 在活动文件上,因此需要将脚本文件添加到脚本列表中才能执行。

核心 objects 和 JavaScript 的功能没有在 UltraEdit 中的任何地方记录,尽管它们也可以在 UltraEdit 脚本中使用。可以在 Mozilla Developer 网站上找到核心功能的文档。

UltraEdit 的附加脚本命令记录在标题为 Scripting commands 的页面的 UE 帮助中。另外还有 View - Views/Lists - Tag List 包含标签组 UE/UES Script Commands 以及 UE/UES宏指令在插入符当前位置的活动文件中快速添加 UE 的脚本或宏命令。