Z是一种流行的shell工具,用于跳转常用目录。它使用"frecency"作为指标,根据关键字完成情况确定您要跳转到的目录。因此,如果我通常cd到~/.ssh
,我可以z ssh
跳到那里。
我的问题是如何在Emacs中使用相同的功能?也就是说,我希望能够使用ido-find-file
或类似的东西,但只需键入几个字符即可跳转到我想要的目录。希望解决方案可以合并z
本身,以便它使用z
已经记录的频率指标。
答案 0 :(得分:1)
我曾经使用过z,但之后我找到了fasd,它受到了autojump,z或v的启发,我发现它更强大,如果我记得很清楚,那是因为:
cd
结果或使用mplayer
或您的编辑或其他命令d
别名来更改目录。无论如何,有一个emacs包用它来查找文件:https://github.com/steckerhalter/emacs-fasd 这很酷,但它并不像我想的那样具有互动性。
编辑:然后我不得不更新包裹:
(setq fasd-enable-initial-prompt nil) ;; don't ask for first query but fire fuzzy completion straight away.
还有一个尚未填写的用例:
我经常使用emacs'壳模式。当我使用我最喜欢的别名d
时,它有效,但我根本没有完成。在这里,zsh的完成显然是缺失的。所以我想使用ido完成,例如。我写了一个小函数,你可以很容易地适应z:
编辑:完成命令并添加由TAB触发的ido完成。现在输入d
(d后跟一个空格)。如果它不断变化,如果我设法创建一个次要模式,我会发布链接到我的gitlab repo。
修改:我为此功能创建了一种模式:https://gitlab.com/emacs-stuff/fasd-shell/tree/master
;; Use the fasd command line utility to change recently visited directories and more.
(defun fasd-get-path-list (pattern)
"call fasd with pattern and return the list of possibilities"
(s-split "\n" (s-trim (shell-command-to-string (format "fasd -l -R %s" pattern))))
)
(defun fasd ()
"If current shell command is `d something' call fasd"
(interactive)
(let* ((user-input (buffer-substring-no-properties (comint-line-beginning-position)
(point-max))))
(if (and (string= (substring user-input 0 2) "d ")) ;; todo: mapping to use something else than d and change directory.
(progn
;; get what is after "d "
(setq fasd-pattern (buffer-substring-no-properties (+ (comint-line-beginning-position) 2) (point-max)))
(setq fasd-command (concat "cd " (ido-completing-read "cd to: " (fasd-get-path-list fasd-pattern))))
(comint-kill-input)
(insert fasd-command)
(comint-send-input)
))))
;; Use TAB as in normal shell. Now we have even better completion than in zsh !
(define-key shell-mode-map (kbd "<tab>") 'fasd) ;; works like a charm :)
作为旁注,我不经常使用它,因为我使用shell-here和shell-pop在当前缓冲区的目录中打开shell(一个下拉终端,如guake for侏儒)。
答案 1 :(得分:0)
在项目中,我发现projectile
(Projectile)模式非常有用。
我使用标准键绑定C-p f
或M-x projectile-find-file
。
它对最近使用的文件上的文件名和过滤器进行模糊匹配。