Anyone aware of a solution of how to start the local editor from the remote to open the remote file?
Anyone aware of a solution of how to start the local editor from the remote to open the remote file?
No, in Emacs you always open a file by typing `C-x C-f`. (Unless you rebound it to some other key, in which case make the obvious substitution.)
Any time you hit `C-x C-f` to open a file it defaults to opening files from the working directory of the current buffer. The working directory of the eshell buffer is on the remote server, so the default list of files that you see are all the ones you were already looking at with `ls`. You can start typing a filename and autocomplete will do the rest.
This is an even deeper and more convenient composition of the shell and the editor than having special commands for tasks like opening a remote file in the local editor.
`C-x C-f` calls the `find-file` function which can be called directly from eshell
All Emacs Lisp functions are Eshell commands. Say 'find-file <filename>' at Eshell and you're in.
https://www.masteringemacs.org/article/running-shells-in-ema...
Try some variant of this in your remote .bash_profile or what-not:
if [ "$PS1" ]; then
export PS1='\h:\w\$ '
if [[ "x${TERM}" = "xeterm" || "x${TERM}" = "xeterm-color" ]]; then
function set-eterm-dir {
echo -e "\033AnSiTu" $(whoami)
echo -e "\033AnSiTc" $(pwd)
echo -e "\033AnSiTh" $(hostname -f)
}
PROMPT_COMMAND=set-eterm-dir
fi
fi
Now, locally, invoke M-x ansi-term, then within the ansi-term ssh to the remote machine. Change dirs, hit C-x C-f to open a file in the current (remote) directory.See also the ansi-term hints on emacswiki
https://www.emacswiki.org/emacs/AnsiTermHints#h5o-5
or the comments in /usr/local/share/emacs/*/lisp/term.el
Edit: formatting
db48x has a great answer below.
for i in "$@"; do
ssh "${SSH_CONNECTION%% *}" emacsclient --no-wait "/ssh:$(hostname):$(realpath "$i")"
done
should work.For best results, use ssh-agent + agent forwarding to avoid password prompts.
/remote:/the/path/<tab>
and autocomplete the file name.Additionally, you can just do dired:
/remote:/the/path <return>
and scroll to the remote file I want to edit and press enterVim has had the ability to open files remotely over ssh, sftp, etc. for a long time using the built-in plugin netwr [1].
Neovim takes it to another level [2]:
Nvim's RPC functionality allows clients to programmatically control Nvim.
Nvim itself takes command-line arguments that cause it to become a client to
another Nvim running as a server. These arguments match those provided by
Vim's clientserver option.
[1]: https://vonheikemen.github.io/devlog/tools/using-netrw-vim-b...