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

发布于 2024-09-27 14:49:36 字数 447 浏览 0 评论 0原文

假设我正在使用 Emacs 编辑 blah.txt 并且我决定 打开 dired 重命名文件 blah.txt。当我按 Cx d RET (或 Cx Cf RET)时,将出现一个 Dired 缓冲区,以显示包含 blah.txt 的目录内容>,但光标不会位于 blah.txt 上。因此,我需要首先搜索我的文件 (Cs blah.txt),将光标放在它上面,然后我可以重命名它 (R)。

如何自动执行或删除步骤 Cs blah.txt

Let's say I am editing blah.txt with Emacs and I decide to open dired to rename the file blah.txt. When I press C-x d RET (or C-x C-f RET), a dired buffer will show up to display the content of the directory containing blah.txt, but the cursor will not be on blah.txt. So I need to search my file first (C-s blah.txt) to place my cursor on it and then I can rename it (R).

How do I automate or remove the step C-s blah.txt?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

時窥 2024-10-04 14:49:36

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

dired-jump is exactly what you want.

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

Then call:

M-x dired-jump

or

M-x dired-jump-other-window
夜灵血窟げ 2024-10-04 14:49:36

您需要Cx Cj

You want C-x C-j.

别念他 2024-10-04 14:49:36

Sunrise Commander 是一款经过大幅改进的指令。它默认执行您需要的操作。

Sunrise Commander is a much improved dired. and it does what you need by default.

还不是爱你 2024-10-04 14:49:36

你可以这样做:

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

然后 dired 中唯一可见的文件将是你当前的文件,并且光标将位于其上。

You can do something like that:

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

Then the only file visible in dired will be your current file and cursor will be right on it.

少女七分熟 2024-10-04 14:49:36

这条建议将满足您的要求:

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

注意:适用于 Cx d,但不适用于 dired 的 Cx Cf 入口点。

This piece of advice will do what you want:

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

Note: Works for C-x d, but not the C-x C-f entry point to dired.

烂人 2024-10-04 14:49:36
$ emacs --version
GNU Emacs 24.3.1

在 .emacs 中:

(require 'dired-x)

现在 Cx Cj 应该绑定到 dired-jump

$ emacs --version
GNU Emacs 24.3.1

In .emacs:

(require 'dired-x)

Now C-x C-j should be bound to dired-jump.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文