简体   繁体   English

Emacs:在点处插入单词替换字符串查询

[英]Emacs: Insert word at point into replace string query

Is there an analogue to inserting the word after point into the isearch query by hitting Cw after Cs but for the replace string (and replace regexp) queries? 通过在Cs之后点击Cw但是对于替换字符串(并替换regexp)查询,是否有类似于将点后插入到isearch查询中?

I also enjoy Sacha Chua's modification of Cx inserting whole word around point into isearch: 我也很喜欢Sacha Chua对Cx的修改,将整个单词插入到isearch中:

http://sachachua.com/blog/2008/07/emacs-keyboard-shortcuts-for-navigating-code/ http://sachachua.com/blog/2008/07/emacs-keyboard-shortcuts-for-navigating-code/

This too would be really useful in some cases if it could be used in replace string. 如果可以在替换字符串中使用它,这在某些情况下也非常有用。

I'd be very thankful for any tips! 我会非常感谢任何提示! Thank you! 谢谢!

This will do it, although it isn't as fancy as Cw in isearch because you can't keep hitting that key to extend the selection: 这将做到这一点,但因为你不能不停的按键,扩展选择它不是为Cw在ISEARCH花哨:

(defun my-minibuffer-insert-word-at-point ()
  "Get word at point in original buffer and insert it to minibuffer."
  (interactive)
  (let (word beg)
    (with-current-buffer (window-buffer (minibuffer-selected-window))
      (save-excursion
        (skip-syntax-backward "w_")
        (setq beg (point))
        (skip-syntax-forward "w_")
        (setq word (buffer-substring-no-properties beg (point)))))
    (when word
      (insert word))))

(defun my-minibuffer-setup-hook ()
  (local-set-key (kbd "C-w") 'my-minibuffer-insert-word-at-point))

(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)

EDIT: Note that this is in the standard minibuffer, so you can use it use it anywhere you have a minibuffer prompt, for example in grep, occur, etc. 编辑:请注意,这是在标准迷你缓冲区中,因此您可以使用它在任何有迷你缓冲区提示的地方使用它,例如在grep中,发生等等。

我认为这已经存在于Emacs中了 - 你只需要用MS-%替换然后按下Mn (当迷你缓冲区为空时),这填写了光标下的单词,你可以用更多有用的东西,查看http: //endlessparentheses.com/predicting-the-future-with-the-mn-key.html?source=rss#disqus_thread

Two answers: 两个答案:

  1. Replace+ automatically picks up text at point as the default value when you invoke replace commands. 当您调用replace命令时, Replace +会自动点上的文本作为默认值。

  2. More generally, Icicles does something similar to what scottfrazer's code (above) does, but it is more general. 更一般地, 冰柱做类似于scottfrazer的代码(上)做一些事情,但它更普遍。 At any time, in any minibuffer, you can hit M-. 在任何时候,在任何迷你缓冲区中,你都可以击中M-。 (by default) to pick up text ("things") at point and insert it in the minibuffer. (默认情况下)在点处拾取文本(“东西”)并将其插入迷你缓冲区。 You can repeat this, to either (a) pick up successive things (eg words) of the same kind, accumulating them like Cw does for Isearch, or (b) pick up alternative, different things at point. 您可以重复这一点,以(a)获取相同类型的连续事物(例如单词),像Cw那样为Isearch积累它们,或者(b)选择其他不同的东西。 More explanation here . 这里有更多解释。

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

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