dired 中移动文件后,最快访问目标目录的方法是什么?

移动文件之后,想跳转到刚刚移动文件所到目录,有现成的方法么?或是怎么设计交互比较好?

可以写个新命令,包装一下移动和跳转目录两个命令。

用两个 dired buffer 分别打开源目录和目标目录(此时按 R 会把另一个目录设为默认目录),再移动,这样就没有这个问题了。

1 个赞

consult 用户,可以使用上面这个package . 配合recentf 记录住最近访问的目录。

(defun vmacs-recentf-keep-p (file)
  "Return non-nil if FILE should be kept in the recent list.
It handles the case of remote files as well."
  (cond
   ((file-remote-p file nil t) (file-readable-p file))
   ((file-remote-p file) nil)           ;不记录tramp path
   ((file-readable-p file))))
(setq recentf-keep '(vmacs-recentf-keep-p))

;; Track opened directories
(defun recentf-track-opened-dir ()
  (and default-directory
       (recentf-add-file default-directory)))

(add-hook 'dired-mode-hook #'recentf-track-opened-dir)

;; Track closed directories
;; (advice-add 'recentf-track-closed-file :override
;;             (defun recentf-track-closed-advice ()
;;               (cond (buffer-file-name (recentf-remove-if-non-kept buffer-file-name))
;;                     ((equal major-mode 'dired-mode)
;;                      (recentf-remove-if-non-kept default-directory)))))

;; (require 'consult-dired-history)
(setq consult-dir-project-list-function #'(lambda()nil)) ;不使用consult-dir--source-project
;; (setq consult-dir-project-list-function #'consult-dir-project-dirs)
(setq-default consult-dir-sources
              '(consult-dir--source-default
                consult-dir--source-recentf
                ;; consult-dir--source-project
                consult-dir--source-tramp-ssh))

(define-key minibuffer-local-completion-map (kbd "C-M-s-j") #'consult-dir)
(define-key minibuffer-local-completion-map (kbd "C-M-s-l") #'consult-dir-jump-file) ;locate
(define-key global-map (kbd "C-x d") #'consult-dir)
(setq consult-dir-shadow-filenames nil)
(setq consult-dir-default-command #'consult-dir-dired)
(with-eval-after-load 'consult-dir
  (defvar consult-dir--source-project-items (plist-get consult-dir--source-project :items))
  (plist-put consult-dir--source-project
             :items #'(lambda() (mapcar #'vmacs-short-filename  (funcall consult-dir--source-project-items))))
  (plist-put consult-dir--source-recentf
             :items #'(lambda() (mapcar #'vmacs-short-filename  (consult-dir--recentf-dirs))))
  (plist-put consult-dir--source-default
             :items #'(lambda() (mapcar #'vmacs-short-filename  (consult-dir--default-dirs))))

  )

这是我的配置 可以参考vmacs/conf-icomplete.el at master · jixiuf/vmacs · GitHub

我的用法是 先在dired 中访问目标目录(它会被recentf记录下来) 然后再回去(回去很快的, 直接用consul-dir 选中最近访问的目录即可。我是绑定到","上)

(define-key dired-mode-map (kbd ",") #'consult-dir)

然后C 执行dired-do-copy 然后 在minibuffer中调用consult-dir 列出最近访问的目录, 选中相应目录后,就把把选中的目录粘贴到minibuffer了。 Feb-20-2023 10-34-56

2 个赞