counsel-fzf 目录设定问题, 以及 counsel-find-file优先级的问题

我想利用counsel-fzf进行模糊搜索,但是我想设置在~目录下进行搜索 我设置 (setq-default counsel–fzf-dir “/home/xxx/”) (xxx为我的用户名) 但是我发现一旦我进入到别的目录(比如~/.emacs.d)后, 我在运行counsel-fzf此时搜索的目录就变成了.emacs.d/ 。 请问我应该如何设置才能满足我的需求。

另外 counsel-find-file 的排序很奇怪 比如~目录下有 note 和 .emacs.d 两个目录。 当我运行counsel-find-file后输入.e 。此时光标默认在note目录上,而不是.emacs.d。请问这个问题有没有什么方法可以解决?

counsel-fzf-dir 每次在调用 counsel-fzf 时会被用特定的方式重新赋值。具体行为你可以看代码(简单来说就是先用传给 counsel-fzf 的 intital-dir,没有则调用 counsel-fzf-dir-function

你想要默认从 home 走可以去设置 counsel-fzf-dir-function。 但我不建议这个方式,因为如果你用 projectile 或者 project 的话,会破坏你在项目下用 counsel-fzf。

我推荐的做法是自己写一个函数,可以用 (let ((default-directory "your path") (counsel-fzf)) 或者 (counsel-fzf nil "your path")

1 个赞

ivy排序推荐上prescient。

  ;; --no-sort is much faster
  (setq counsel-fzf-cmd "fzf --no-sort -f \"%s\"")

(defun jester/fzf-somewhere (&optional start-dir)
    "Do `counsel-fzf' in directory START-DIR.
If called interactively, let the user select start directory first."
    (interactive)
    (unless start-dir
      (ivy-read "dir to start fzf: " #'read-file-name-internal
                :matcher #'counsel--find-file-matcher
                :action (lambda (selection) (setq start-dir selection))
                :history 'file-name-history
                :keymap counsel-find-file-map))
    (let ((default-directory start-dir))
      (counsel-fzf)))
1 个赞