如题,原始搜索,ivy都是,occur似乎都是包含整行。
比如: this is a test
搜索is,我相要复制is is
,而不是整行。
如题,原始搜索,ivy都是,occur似乎都是包含整行。
比如: this is a test
搜索is,我相要复制is is
,而不是整行。
没搞懂你这个能干什么,
很奇怪的需求.
正则式搜索的时候,提取搜到的内容,做进一步的处理。比如搜到数字,在电子表格中计算
使用 occur
,原生键位绑定是:
C-u M-s o 然后输入正则
或你可以使用 M-x 即 C-u M-x occur 然后输入正则
C-u 的效果是只取匹配内容,不显示文件路径,匹配行等信息。
谢谢,这个可行。
在 EmacsWiki: Occur Mode 上找到一个函数,保持搜索时的位置,其他内容换成空格。
(defun occurrences (regexp &rest ignore)
"Show all matches for REGEXP in an `occur' buffer."
;; keep text covered by occur-prefix and match text-properties
(interactive (occur-read-primary-args))
(occur regexp)
(with-current-buffer (get-buffer "*Occur*")
(let ((inhibit-read-only t)
delete-from
pos)
(save-excursion
(while (setq pos (next-property-change (point)))
(goto-char pos)
(if (not (or (get-text-property (point) 'occur-prefix)
(get-text-property (point) 'occur-match)))
(if delete-from
(delete-region delete-from (point))
(setq delete-from (point)))
(when delete-from
(delete-region delete-from (point))
(if (get-text-property (point) 'occur-prefix)
(insert "\n")
(insert " ")))
(setq delete-from nil)))))))