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

use*_*978 3 emacs ssh shell terminal

我的设置:

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

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

我知道从shell打开文件的唯一方法是emacs -nw再次执行,这不太方便,因为a)我没有保持shell打开,b)它实际上是一个不同的Emacs会话,所以例如"yank"缓冲区"是不同的.

编辑:如果有一个不同的/更好的方式来使用Emacs的远程服务器,我只是感兴趣; 这就是我想要做的.

abo*_*abo 6

最好使用tramp.

我有这个快捷方式(我称之为smex):

(defun connect-remote ()
  (interactive)
  (dired "/user@domain.com:/"))
Run Code Online (Sandbox Code Playgroud)

这将在遥控器上打开一个直接缓冲区.你只需将它用作任何直接缓冲区.

我有一个函数从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")))
Run Code Online (Sandbox Code Playgroud)

这是我使用的快捷方式:

(define-key dired-mode-map (kbd "`") 'dired-open-term)
Run Code Online (Sandbox Code Playgroud)