gpt4 book ai didi

shell - Emacs shell 模式在缓冲区中打开文件

转载 作者:行者123 更新时间:2023-12-01 09:41:35 24 4
gpt4 key购买 nike

我的设置:

  • Emacs 终端模式(emacs -nw)
  • 在其中,使用 shell 模式(通过 M-x ansi-term 调用)
  • 在这个 shell 中,使用 ssh 连接到远程服务器

假设我正在 shell 中浏览远程服务器并找到一个我想要编辑的文件。是否有命令将其作为并行缓冲区/窗口打开?

我知道从 shell 打开文件的唯一方法是再次执行 emacs -nw,这不太方便,因为 a) 我没有保持 shell 打开和 b)这确实是一个不同的 Emacs session ,因此例如“yank 缓冲区”是不同的。

编辑:如果有一种不同/更好的方式来使用 Emacs 与远程服务器一起工作,我同样感兴趣;这就是我想要做的。

最佳答案

最好用tramp。

我有这个快捷方式(我用 smex 调用它):

(defun connect-remote ()
(interactive)
(dired "/user@domain.com:/"))

这会在 Remote 上打开一个 dired 缓冲区。您只需将其用作任何 dired 缓冲区即可。

我有一段时间可以从 dired 中打开一个术语,但我已经刚刚添加了一个从tramp dired缓冲区进行ssh的选项:

(defun dired-open-term ()
"Open an `ansi-term' that corresponds to current directory."
(interactive)
(let ((current-dir (dired-current-directory)))
(term-send-string
(terminal)
(if (file-remote-p current-dir)
(let ((v (tramp-dissect-file-name current-dir t)))
(format "ssh %s@%s\n"
(aref v 1) (aref v 2)))
(format "cd '%s'\n" current-dir)))))

(defun terminal ()
"Switch to terminal. Launch if nonexistent."
(interactive)
(if (get-buffer "*terminal*")
(switch-to-buffer "*terminal*")
(term "/bin/bash")))

这是我使用的快捷方式:

(define-key dired-mode-map (kbd "`") 'dired-open-term)

关于shell - Emacs shell 模式在缓冲区中打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21523142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com