2010-10-14 62 views
7

假设我在用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)。打开dired并选择与前一个缓冲区关联的文件?

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

回答

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 
+0

如果按照手册中的说明操作,您将获得正确的键绑定:'Ch ig''(dired-x)可选的安装Dired Jump'' RET' – phils 2014-08-23 06:25:38

1

你可以做这样的事情:

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

然后在dired可见的将是您当前的文件和光标的唯一文件将是正确的就可以了。

5

你想要C-x C-j

+0

什么是'C-x C-j'?它不受文本缓冲区或直接缓冲区的限制(Emacs 23.2)。 – 2010-10-14 14:06:36

+4

@Trey:'C-x C-j'绑定到'dired-jump',但只有当'dired-x'被加载时。 (我认为有一个Emacs策略,'dired-x'不符合这里。) – Gilles 2010-10-14 19:53:29

+0

谢谢,吉尔斯;我没有意识到它不是默认绑定的。 – offby1 2010-10-19 03:50:28

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)))) 

注:Works的C-X d,而不是C-X C-F切入点dired。

0
$ emacs --version 
GNU Emacs 24.3.1 

在的.emacs:

(require 'dired-x) 

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

相关问题