如何从我的 ~/.ssh/config 中让 Emacs TRAMP 提供补全?

Rya*_*son 2 emacs sftp autocomplete tramp

当我想使用 TRAMP 在 Emacs 中通过 sftp 访问远程文件时,我希望 Emacs 为我提供来自我的 ssh 配置中主机名的补全。我怎样才能做到这一点?

例如,如果我的 ssh 配置中有两个主机,“alpha”和“bravo”,当我/sftp:a在 find-file 提示符下键入时,它应该完成“alpha”。

Gil*_*il' 5

远程访问记录在TRAMP 手册中。您需要有关自定义完成的部分。把这样的东西放在你的~/.emacs

(setq my-tramp-ssh-completions
      '((tramp-parse-sconfig "~/.ssh/config")
        (tramp-parse-shosts "~/.ssh/known_hosts")))
(mapc (lambda (method)
        (tramp-set-completion-function method my-tramp-ssh-completions))
      '("fcp" "rsync" "scp" "scpc" "scpx" "sftp" "ssh"))
Run Code Online (Sandbox Code Playgroud)