【问题标题】:Use z (jump around) in Emacs to find directories在 Emacs 中使用 z(跳转)查找目录
【发布时间】:2014-08-13 03:52:08
【问题描述】:

Z 是一个流行的 shell 工具,用于跳转常用目录。它使用"frecency" 作为指标,根据关键字完成来确定您打算跳转到哪个目录。所以如果我经常cd到~/.ssh,我可以z ssh跳转到那里。

我的问题是如何在 Emacs 中获得相同的功能?也就是说,我希望能够使用ido-find-file 或类似的东西,但只需键入几个字符即可跳转到我想要的目录。希望该解决方案可以合并z 本身,以便利用z 已经记录的频率指标。

【问题讨论】:

  • 不完全是您问题的答案,但也许您应该查看Icicles。召唤@Drew。
  • @tripleee:抱歉,Icicles 并没有开箱即用的任何东西来帮助解决这个问题。它使您可以轻松访问最近使用的文件 - 而不仅仅是目录。 (它利用recentf-list。)我猜那里有些东西很适合这个请求,但我不知道。使用Bookmark+,您可以使用 Dired 书签,但书签创建不是自动的(您需要按一个键,即使是自动命名的书签)。 (或者您可以让 Emacs 文件缓存命令自动创建书签 - 选项 bmkp-autofile-filecache。)
  • @tripleee:好吧,我收回了书签永远不会自动的部分。 Bookmark+ 文档的This section 描述了自动书签功能。这是否在这里可能有用,我不能说。
  • @tripleee:最后一条评论:添加使用谓词来控制自动书签的可能性很容易(例如,书签只能在 Dired 缓冲区或满月时自动创建或任何)。目前控制自动创建的唯一参数是 (a) 空闲时间和 (b) 与其他自动书签的距离。
  • 您好,您找到适合您的解决方案了吗?

标签: shell emacs cd


【解决方案1】:

我用过一次 z,但后来我发现了 fasd,它的灵感来自 autojump、z 或 v,我发现它更强大,如果我记得很清楚,这是因为:

  • 它不仅可以查找目录,还可以查找文件
  • 它可以cd 一个结果或使用mplayer 或您的编辑器或其他命令
  • 完成更好,特别是对于 zsh(如果我没记错的话)。问题是,我经常使用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 shell 中使用 fasd(或 autojump 或 z)完成?

我经常使用 emacs 的 shell 模式。当我使用我最喜欢的别名d 时,它可以工作,但我根本没有完成。在这里,zsh 的补全显然是缺失的。例如,我想使用 ido 补全。我写了一个小函数,你可以很容易地适应 z:

edit:完成命令并添加由TAB触发的ido完成。现在输入d(d 后跟一个空格)。如果它不断变化并且我设法创建了一个次要模式,我会将链接发布到我的 gitlab 存储库。

编辑:我为此功能创建了一个模式: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-hereshell-pop(一个下拉终端,如 gnome 的 guake)打开 shell。

【讨论】:

【解决方案2】:

在一个项目中,我发现projectile (Projectile) 模式非常有用。

我使用标准键绑定C-p fM-x projectile-find-file

它对最近使用的文件的文件名和过滤器进行模糊匹配。

【讨论】:

  • 我使用helm-ls-git-ls 在项目中查找文件。我需要的是一种快速跳转到项目目录的方法。
  • 您可能对 projectile 的 helm 界面感兴趣,可以切换定义了多个动作的项目,其中之一是在项目目录中打开 dired。这是一个即将推出的功能:github.com/bbatsov/projectile/commit/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多