简体   繁体   English

我怎么能在输入内容时使用像isearch-forward这样的查询替换

[英]how could I using query-replace like isearch-forward while typing something

虽然isearch-forward作为命令运行,但我输入的上下文将在当前缓冲区中突出显示,但是运行查询替换时不会高亮显示那个,我怎样才能使它成为高亮?

Use isearch-query-replace . 使用isearch-query-replace It highlights the string to be replaced. 它突出显示要替换的字符串。

  1. It sounds like you are saying that query-replace does not highlight all of the matching occurrences. 听起来你说query-replace不会突出显示所有匹配的事件。 Is that right? 是对的吗? It should highlight them. 应该突出它们。 If it does not, then try starting Emacs without your init file: emacs -Q . 如果没有,那么尝试在没有init文件的情况下启动Emacs: emacs -Q If that shows no lack of highlighting then recursively bisect your init file to find the culprit. 如果显示不缺少突出显示,则递归地将您的init文件一分为二,以找到罪魁祸首。

  2. @Rocky mentioned isearch-query-replace . @Rocky提到了isearch-query-replace That doesn't change highlighting (which should already be turned on), but what it does do is let you start query-replacing while you are isearching, using the last search string as the pattern for the text to be matched by query-replace . 这不会改变突出显示(应该已经打开),但它的作用是让你在isearching时开始查询替换,使用最后一个搜索字符串作为query-replace匹配文本的模式。

  3. An alternative to query-replace, useful especially if you have relatively few replacements you want to make and there are lots of matches, is to use on-demand replacement while isearching . 查询替换的替代方法,特别是如果您想要进行相对较少的替换并且存在大量匹配,则可以在isearching时使用按需替换 For that you need library Isearch+ . 为此你需要库Isearch +

    To replace any given search hit on demand, just hit CM-RET . 要按需替换任何给定的搜索命中,只需点击CM-RET With a prefix arg, CM-RET prompts you for the replacement text (the default is to replace with no text, which means to delete the hit). 使用前缀arg, CM-RET会提示您输入替换文本(默认情况下将替换为无文本,这意味着删除匹配)。 You can thus change the replacement text anytime , within the same Isearch invocation. 因此,您可以在同一个Isearch调用中随时更改替换文本

    After replacing the search hit, CM-RET moves to the next one. 替换搜索命中后, CM-RET移动到下一个。 So you can just use it repeatedly if you want to replace several successive search hits. 因此,如果您想要替换几个连续的搜索命中,您可以重复使用它。 Or use Cs to skip replacing the current hit and move to the next one. 或者使用Cs跳过替换当前命中并移动到下一个命中。

    On-demand Isearch replacement works also for regexp searching, and just as for query-replacing, the replacement text can be either inserted literally, as is, or interpreted as in query-replace-regexp . 按需Isearch替换也适用于正则表达式搜索,就像查询替换一样,替换文本可以按字面顺序插入,也可以在query-replace-regexp In the latter case, you can use \\& , \\=\\N , \\# , \\, and \\? 在后一种情况下,您可以使用\\&\\=\\N\\#\\,\\? . You can use CM-` anytime during Isearch to toggle whether replacement text is used literally or interpreted per the special regexp-replacement constructs. 您可以在Isearch期间随时使用CM-` to来切换是否按字面使用替换文本或根据特殊的regexp替换构造进行解释。

The following packages provide live highlighting and replacement previewing for query replacing, as well as additional features: 以下软件包为查询替换提供实时突出显示和替换预览,以及其他功能:

I currently use visual-regexp-steroids.el . 我目前使用visual-regexp-steroids.el

All three packages can be installed from MELPA . 所有三个包都可以从MELPA安装。

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

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