【问题标题】:Open dired and select the file associated with the previous buffer?打开 dired 并选择与前一个缓冲区关联的文件?
【发布时间】:2011-04-25 09:52:56
【问题描述】:

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

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

【问题讨论】:

    标签: emacs elisp rename dired


    【解决方案1】:

    你可以这样做:

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

    那么 dired 中唯一可见的文件将是您当前的文件,并且光标将就在它上面。

    【讨论】:

      【解决方案2】:

      你想要C-x C-j

      【讨论】:

      • C-x C-j 是什么?它没有绑定在文本缓冲区或 dired 缓冲区 (Emacs 23.2) 中。
      • @Trey: C-x C-j 绑定到 dired-jump,但仅在加载 dired-x 时。 (我认为这里有 dired-x 不遵守的 Emacs 政策。)
      • 谢谢,吉尔;我没有意识到默认情况下它没有绑定。
      【解决方案3】:

      Sunrise Commander 是一个大大改进的 dired。默认情况下它会满足您的需求。

      【讨论】:

        【解决方案4】:

        这条建议会如你所愿:

        (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,但不适用于 dired 的 C-x C-f 入口点。

        【讨论】:

          【解决方案5】:

          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
          

          【讨论】:

          • 如果您按照手册中的说明进行操作,您还将获得正确的键绑定:C-h i g(dired-x) Optional Installation Dired JumpRET
          【解决方案6】:
          $ emacs --version
          GNU Emacs 24.3.1
          

          在 .emacs 中:

          (require 'dired-x)
          

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2010-12-22
            • 1970-01-01
            • 2011-04-17
            • 2016-05-05
            相关资源
            最近更新 更多