在Emacs的dired中,如何查找/访问多个文件?

39
如果我有多个标记文件,那么在Emacs中如何找到/访问所有这些标记文件,而不是在每个文件上运行dired-find-file
是否有内置命令,还是需要一些额外的Lisp代码?
3个回答

36

在 Emacs 23.2 及以上版本中,有一个名为 dired-x.el 的模块可供使用,它可以让你使用一个命令来实现你想要的功能。加载它之后(通常只需要用(load "dired-x")),你就可以调用函数 dired-do-find-marked-files 来实现了。下面是它的内置文档:

(dired-do-find-marked-files &optional NOSELECT)

Find all marked files displaying all of them simultaneously.
With optional NOSELECT just find files but do not select them.

The current window is split across all files marked, as evenly as possible.
Remaining lines go to bottom-most window.  The number of files that can be
displayed this way is restricted by the height of the current window and
`window-min-height'.

To keep dired buffer displayed, type C-x 2 first.
To display just marked files, type C-x 1 first.

因此,在加载 dired-x 后,您可以使用 M-x dired-do-find-marked-files RET,然后您将获得与您的问题完全相同的结果:所有标记的文件都将被访问,就像您对所有这些文件运行了 dired-find-file


我的dired-mode不认识这个命令,而且我使用的是23.4版本。 - Malabarba
1
@Bruce Connor:可能您没有安装dired-x。尝试在.emacs中添加(add-hook 'dired-load-hook (function (lambda () (load "dired-x")))) - Adobe
3
在Emacs 24.4中,“F”键是dired-do-find-marked-files的键盘快捷键。 - thdox
我还要补充一点,你可以使用前缀参数来防止Emacs将框架分割成每个打开的文件一个新窗口。例如,你可以使用C-u M-x dired-do-find-marked-files,或者使用默认的按键绑定C-u C-F - dpritch

27

如果你将以下代码添加到你的.emacs文件中,你就可以通过按键“F”打开文件。

(eval-after-load "dired"
  '(progn
     (define-key dired-mode-map "F" 'my-dired-find-file)
     (defun my-dired-find-file (&optional arg)
       "Open each of the marked files, or the file under the point, or when prefix arg, the next N files "
       (interactive "P")
       (let* ((fn-list (dired-get-marked-files nil arg)))
         (mapc 'find-file fn-list)))))

如果需要的话,显然可以覆盖内置的 'f'。


6
谢谢!小的风格问题,但在这种情况下您不需要使用let*let就足够了)。而且,我们可能只需简化最后一个形式为(mapc 'find-file (dired-get-marked-files nil arg)) - camdez

6
你可以尝试使用 Dired+,它提供了许多扩展功能,包括选择多个文件并查找/查看它们的能力。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接