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.

skeletalmonkey
  • 716
  • 1
  • 8
  • 20

7 Answers7

32

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

:e scp://username@host.com/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.

Cody
  • 3,576
  • 2
  • 21
  • 29
  • 4
    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. – the Tin Man Mar 27 '11 at 10:13
  • 5
    This can be combined with the ControlMaster, ControlPath, and ControlPersist SSH configuration options (see [ssh_config(5)](http://www.openbsd.org/cgi-bin/man.cgi?query=ssh_config)) to make a fairly snappy remote-file interface. – Chris Johnsen Sep 23 '11 at 04:19
  • 1
    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. – styfle Dec 24 '12 at 01:49
19

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

rene
  • 37,946
  • 78
  • 99
  • 132
Ana Betts
  • 71,086
  • 16
  • 135
  • 201
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.

jrwren
  • 15,914
  • 5
  • 32
  • 52
user3397938
  • 61
  • 1
  • 1
5

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/
the Tin Man
  • 150,910
  • 39
  • 198
  • 279
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.

DerMike
  • 13,362
  • 12
  • 45
  • 60
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

romainl
  • 158,436
  • 18
  • 236
  • 264
  • 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. – skeletalmonkey Mar 18 '11 at 04:31
  • @skeletalmonkey Yesterday I played around my idea of using `whoami` but didn't succeed at all. Maybe it's not such a good idea. – romainl Mar 18 '11 at 06:34
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.

ecleel
  • 11,218
  • 13
  • 46
  • 48