在Emacs中转到文件

Nir*_*Nir 48 emacs

在emacs中是否有替代vi"gf"命令?意思是如果实际存在真正的文件名,请尝试立即打开光标下的文件.

谢谢

cjm*_*cjm 73

你想要的find-file-at-point功能(也是别名ffap).默认情况下,它不受键的约束,但您可以使用

M-x ffap
Run Code Online (Sandbox Code Playgroud)

或者,您可以输入您的.emacs文件:

(ffap-bindings)
Run Code Online (Sandbox Code Playgroud)

这将替换许多基于-Based版本的普通find-file键绑定(例如C-x C-f)ffap.有关ffap.el详细信息,请参阅评论.


Nir*_*Nir 6

谢谢,它工作得很好,但不知何故vi(gf)版本仍然有点聪明.我认为它会查看搜索路径的某个路径变量.

我做了一些不必要的复杂但对我有用的东西(仅限linux).它使用"locate"命令搜索光标下的路径.我想通过首先搜索当前文件的相对路径可以使它变得更聪明.对不起我糟糕的elisp技能......它可能以更好的方式实现.

放入.emacs,然后使用Mx goto-file

(defun shell-command-to-string (command)
  "Execute shell command COMMAND and return its output as a string."
  (with-output-to-string
    (with-current-buffer standard-output
      (call-process shell-file-name nil t nil shell-command-switch command))))

(defun goto-file ()
  "open file under cursor"
  (interactive)
  (find-file (shell-command-to-string (concat "locate " (current-word) "|head -c -1" )) ))
Run Code Online (Sandbox Code Playgroud)

  • 我的Emacs已经在simple.el中定义了shell-command-to-string (2认同)