답변:
시작 위치를 계속 유지하면서 지원되는 것으로 보이지 않습니다. (검색이 끝날 때 버퍼의 시작 부분으로 줄 바꿈하는 방법은 없습니다.)
가장 좋은 방법은 M-<버퍼의 시작 부분으로 이동 한 다음을 query-replace
눌러 C-uC-spaceC-uC-space시작 지점으로 되돌아가는 것입니다.
transient-mark-mode
켜져 있을 때 작동 합니다. 그렇지 않으면 C-SPC C-SPC
일시적으로 가능하게 할 것이다transient-mark-mode
다음 명령을 emacs 초기화 파일에 추가하고 선택한 키 입력에 바인딩 할 수 있습니다.
(defun replace-regexp-entire-buffer (pattern replacement)
"Perform regular-expression replacement throughout buffer."
(interactive
(let ((args (query-replace-read-args "Replace" t)))
(setcdr (cdr args) nil) ; remove third value returned from query---args
args))
(save-excursion
(goto-char (point-min))
(while (re-search-forward pattern nil t)
(replace-match replacement))))
init.el
파일에 이것을 추가 M-%
하여 기본적으로 전체 버퍼에서 단어를 바꾸는 동작을 업데이트 할 수 있습니다 .
(defun my/query-replace (from-string to-string &optional delimited start end)
"Replace some occurrences of FROM-STRING with TO-STRING. As each match is
found, the user must type a character saying what to do with it. This is a
modified version of the standard `query-replace' function in `replace.el',
This modified version defaults to operating on the entire buffer instead of
working only from POINT to the end of the buffer. For more information, see
the documentation of `query-replace'"
(interactive
(let ((common
(query-replace-read-args
(concat "Query replace"
(if current-prefix-arg " word" "")
(if (and transient-mark-mode mark-active) " in region" ""))
nil)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
(if (and transient-mark-mode mark-active)
(region-beginning)
(buffer-end -1))
(if (and transient-mark-mode mark-active)
(region-end)
(buffer-end 1)))))
(perform-replace from-string to-string t nil delimited nil nil start end))
;; Replace the default key mapping
(define-key esc-map "%" 'my/query-replace)
그리고 같은 행동을 얻으려면 query-replace-regexp
:
(defun my/query-replace-regexp (regexp to-string &optional delimited start end)
"Replace some things after point matching REGEXP with TO-STRING. As each
match is found, the user must type a character saying what to do with
it. This is a modified version of the standard `query-replace-regexp'
function in `replace.el', This modified version defaults to operating on the
entire buffer instead of working only from POINT to the end of the
buffer. For more information, see the documentation of `query-replace-regexp'"
(interactive
(let ((common
(query-replace-read-args
(concat "Query replace"
(if current-prefix-arg " word" "")
" regexp"
(if (and transient-mark-mode mark-active) " in region" ""))
t)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
(if (and transient-mark-mode mark-active)
(region-beginning)
(buffer-end -1))
(if (and transient-mark-mode mark-active)
(region-end)
(buffer-end 1)))))
(perform-replace regexp to-string t t delimited nil nil start end))
;; Replace the default key mapping
(define-key esc-map [?\C-%] 'my/query-replace-regexp)
이것은 현재 사용중인 솔루션이며 버퍼의 시작 부분부터 시작하여 교체 후 이전 지점으로 돌아갑니다.
(defun query-replace-from-top ()
(interactive)
(let ((orig-point (point)))
(save-excursion
(goto-char (point-min))
(call-interactively 'query-replace))
(message "Back to old point.")
(goto-char orig-point)))
(bind-key* "M-%" 'query-replace-from-top)