2

I'm currently using vim (actually neovim) as my IDE for writing and executing GNU R-code (using the Nvim-R-plugin, see also https://github.com/jalvesaq/Nvim-R, which serves as my REPL), which works great on my local machine. When having higher workloads or demands, I'm ssh-ing into a remote machine, installing my nvim plugins and running nvim as a "local" application on the server.

Recently I realized that Emacs has the ingenious TRAMP mode (Transparent Remote Access, Multiple Protocols, see also https://www.emacswiki.org/emacs/TrampMode), which allows to not only open files remotely, but also execute commands on a remote machine. From what I understand this means that I could use Emacs as a REPL (e.g. using ESS), writing code using my local Emacs-instance, but executing it on a remote machine where I have GNU R installed (see also https://ess.r-project.org/Manual/ess.html#ESS-processes-on-Remote-Computers).

I'd be interested to know if something similar exists for vim or neovim. I'm aware that I can edit files remotely using

vim scp://USER@SERVER:PORT//absolute/path/to/file

or

vim
:e scp://USER@SERVER:PORT//absolute/path/to/file

but from what I understand this actually creates a temporary copy of the file on my local machine; when running my Nvim-R-REPL this opens the working directory locally on /tmp/something.

I thought about experimenting with vim-slime (see https://github.com/jpalardy/vim-slime), repl.nvim (see https://github.com/HiPhish/repl.nvim) or neoterm (see https://github.com/kassio/neoterm), but I'm unsure if I could be able to try and replicate an Emacs-like experience.

Any ideas? Has anybody achieved something similar?

4
  • Personally I'd just run Vim in an SSH session to the remote host... If you like the Emacs features but prefer Vim modal editing, check out evil-mode which implements modal interface, pretty close to full Vim, in Emacs.
    – filbranden
    Sep 6 '20 at 3:20
  • 1
    @filbranden: I also thought about emacs with evil-mode. To be honest, I was already thinking about swiching to emacs, but after more than 1K lines of .vimrc or init.vim this step isn't taken lightly - especially since I assume it would take quite some time until I would have made made my emacs-configuration as tuned to my needs as it is with vim/neovim and I would reach the same level of productivity.
    – n0542344
    Sep 7 '20 at 7:20
  • 1
    Yeah... Like I said, personally I'd just run Vim in an SSH session to the remote host... :-) I guess most Vimmers tend to be more comfortable in the terminal, while the text version of Emacs is crappy, that's why Emacs folks end up building something like Tramp while Vimmers just run it on the target host... You might want to consider asking this question (or asking to get it migrated) at the Vi and Vim stack, someone there might have a better idea or know of an appropriate plug-in for you. Cheers!
    – filbranden
    Sep 7 '20 at 7:29
  • If you want to move this to Vi and Vim, just delete it from here and repost there. If we migrate it, it will appear on the target site as though asked on the 27th of august, so it's much cleaner to simply repost it after deleting.
    – terdon
    Sep 8 '20 at 8:42
0

Disclaimer: I answered this question already on vi.SE and only duplicated the answer for completeness sake.


I still haven't found the perfect solution, but one that works for me reasonably well: by using vim-slime (which is written in only vimscript).

In my config-file (~/.config/nvim/init.vim or ~/.vimrc), I'm using the following line(s):

let g:slime_target = "neovim"
"let g:slime_target = "vimterminal"
"let g:slime_target = "screen"
"let g:slime_target = "tmux"

Only one of them is needed. The first line is used for neovim, but if I'm using vim I use the second one (uncommented). In my workflow I'm ssh-ing into a remote machine, then open the file I want to use (e.g. my script.R or list_of_commands.sh), then create a :vertical split and subsequently open a :terminal, where I can then run e.g. my GNU R-interpreter or a bash. If one prefers to use a terminal multiplexer, the new split can be created using either screen (with Ctrl-a | Ctrl-a l Ctrl-a c) or tmux (with Ctrl-b %) and have the appropriate line from above (uncommented) in the config-file.

When I then invoke the :SlimeSend-command (abbreviated with Ctrl-c Ctrl-c, so the same key-combination has to be pressed twice), the text I'm currently having my cursor on is selected to be send to the target (which, when the configuration is correct and your split is already present, is written in correctly by default).

That might not be as elegant as TRAMP in Emacs, but it works. But if anyone has ideas for improvement, don't hesitate to suggest them!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.