打开dired并选择与前一个缓冲区关联的文件?

时间:2010-10-14 13:16:08

标签: emacs elisp rename dired

假设我正在使用Emacs编辑blah.txt,我决定open dired to rename the file blah.txt。当我按C-x d RET(或C-x C-f RET)时,将显示一个直接缓冲区以显示包含blah.txt的目录的内容,但光标不会在blah.txt上。所以我需要首先搜索我的文件(C-s blah.txt)以将光标放在它上面,然后我可以重命名它(R)。

如何自动执行或删除步骤C-s blah.txt

6 个答案:

答案 0 :(得分:12)

dired-jump正是您想要的。

(autoload 'dired-jump "dired-x" "Jump to dired corresponding current buffer.")
(autoload 'dired-jump-other-window "dired-x" "jump to dired in other window.")

然后致电:

M-x dired-jump

M-x dired-jump-other-window

答案 1 :(得分:5)

您想要C-x C-j

答案 2 :(得分:2)

Sunrise Commander是一个改进得很好的方向。并且它默认执行您需要的操作。

答案 3 :(得分:1)

你可以这样做:

M-: (dired (buffer-name (current-buffer)))

然后,在dired中可见的唯一文件将是您当前的文件,光标将在其上。

答案 4 :(得分:1)

这条建议可以满足您的需求:

(defadvice dired (around dired-jump-to-buffer activate)
  "When running dired, move cursor to the line for the buffer we came from"
  (interactive (list nil nil)) ;; bogus values, will be overwritten below
  (let ((coming-from (buffer-file-name)))
(ad-set-args 0 (dired-read-dir-and-switches ""))
ad-do-it
(when (and coming-from
       (equal (file-truename default-directory) (file-truename (file-name-directory coming-from))))
    (goto-char (point-min))
    (search-forward (file-name-nondirectory coming-from) nil t))))

注意:适用于 C-x d ,但不适用于 C-x C-f 入口点。

答案 5 :(得分:0)

$ emacs --version
GNU Emacs 24.3.1

在.emacs中:

(require 'dired-x)

现在C-x C-j应绑定到dired-jump