Using Macvim over ssh
Asked Answered
L

7

29

My project involves working on a large codebase on a remote server. I'm constantly editing multiple files, so scp'ing files back an forth is not possible. I've got my local Macvim setup just the way I like it, with multiple plugins including ctags.

It is at all possible to use Macvim over ssh in such a way that I am easily able to browse to and open files from within Macvim running locally?

Getting ctags to work without it being installed on the remote server would be even better but I suspect not possible...

Also an issue is the fact that the remote server is setup with someone else's .vimrc that I don't want to use, but can't overwrite.

Lectureship answered 16/3, 2011 at 5:58 Comment(0)
A
20

Use SSHFS from the FUSE for macOS project. https://github.com/libfuse/sshfs

Adult answered 16/3, 2011 at 6:0 Comment(4)
A really elegant solution to this problem, I like it.Klenk
I like this idea, but how well would this work with a large code base?Lectureship
Unless you can type really, really fast, it should be fineAdult
My experience so far is that using expanddrive and gvim is too slow to be workable. I suspect that because gvim simply sees a mount it isn't smart enough limit disk writes to when the user explicitly saves.Xuanxunit
K
34

The following command will open a file in MacVim over ssh:

:e scp://[email protected]/path/to/file

I suspect this might not be completely what you're looking for as it will only give you one file at a time.

If you could mount a share from the target system locally that would work as well.

Klenk answered 16/3, 2011 at 6:1 Comment(3)
If you leave off the filename, and refer to just the directory, vim will present a directory browser for the remote directory, allowing you to select a file that way. It's still only one file at a time, but it's convenient when you don't remember the name.Periapt
This can be combined with the ControlMaster, ControlPath, and ControlPersist SSH configuration options (see ssh_config(5)) to make a fairly snappy remote-file interface.Chamblee
You should mention that this will actually save the file back to the remote machine after you :w. I didn't expect that to happen when I saw scp.Jeremy
A
20

Use SSHFS from the FUSE for macOS project. https://github.com/libfuse/sshfs

Adult answered 16/3, 2011 at 6:0 Comment(4)
A really elegant solution to this problem, I like it.Klenk
I like this idea, but how well would this work with a large code base?Lectureship
Unless you can type really, really fast, it should be fineAdult
My experience so far is that using expanddrive and gvim is too slow to be workable. I suspect that because gvim simply sees a mount it isn't smart enough limit disk writes to when the user explicitly saves.Xuanxunit
P
6

One thing I used to use a lot was to open an X-11 session, then connect to my remote host, and use gvim over X. You'll have a full-GUI version of the editor, it'll look like its running locally, but everything really is running remotely.

Another alternative is to use VNC to remotely control the session on the remote host. There are several VNC clients for the Mac.

You can also use a Mac SFTP or FTP client to connect, then tell it to edit a file or files. If you've configured it to use MacVim as your editor the file I/O will occur through the FTP connection transparently. That's how I edit remote websites when I don't have ssh capability.

MacVim and vim's netrw plugin is very capable though. If you don't pass a filename to edit on the scp://... command, vim will present the usual directory browser letting you select your file from the remote machine and edit it locally. For instance, this opens a connection from my laptop to itself via SSH and shows me the home directory inside vim:

vim scp://greg@localhost//Users/greg/
Periapt answered 27/3, 2011 at 10:24 Comment(1)
I've just tried open scp://hostname/ in my mvim window, and it works beautifully.Bernita
B
6

MacFUSE as suggested above is no longer maintained. Luckily there is a successor, OSXFUSE.

I use MacVim on OS X 10.9 with OSXFUSE and SSHFS to edit code on a remote Linux server. I experience a short delay (1-3 seconds) when saving a textfile, but apart from that, it is like working with your local filesystem.

Bandler answered 9/3, 2014 at 22:38 Comment(0)
P
2

As for the .vimrc part of your question the documentation states that parameter -u may help you.

-u {vimrc} The file {vimrc} is read for initializations.

Purism answered 16/3, 2011 at 9:25 Comment(1)
oh, thats quite handy. Thanks.Lectureship
A
0

scp-ing for each files is going to be a pain in your ass.

While SSHFS with MacFuse works, it can be really really slow. I tried it a couple of times at work with a huge pipe to a close server and, while the idea seemed elegant at first, it was a maddening beachball-ridden experience.

How is the server setup exactly? Do you log in as someone else or as yourself with your own /home/username?

If the later you can easily put all your Vim-related stuff in your home directory and use the server's Vim almost like you'd use MacVim. You can even build ctags somewhere in your home directory and use it…

If you login as yourself but don't have a home directory you could put your Vim stuff somewhere you have write access and add its path to the master .vimrc with an if/else checking for your username.

I haven't tested this solution but I use a similar technique to load different settings wether I'm on my Mac or on my Ubuntu box:

if has("gui_running")

  "various gui settings

  let os=substitute(system('uname'), "\n", "", "")
  if os == "Darwin" || os == "Mac"

    "Mac-specific settings

  elseif os == "Linux"

    "Linux-specific settings

  endif

endif

Maybe with the command whoami

Antivenin answered 16/3, 2011 at 8:30 Comment(2)
In one setup I get to log in as my own user, to my own home folder, which makes things easier. But another project involves logging onto a friends server without my own user directory. I guess I can put enough cases in my .vimrc to catch all the different situations.Lectureship
@Lectureship Yesterday I played around my idea of using whoami but didn't succeed at all. Maybe it's not such a good idea.Antivenin
C
0

MacFuse is MAC version of fuse. But unfortunately they no longer maintained the project and it have some problems with Snow Leopard but there is a fix.

Commonplace answered 20/12, 2011 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.