1

I'm editing Unity 3D .cs files in gVim on Windows 7, I'd like when I double click a file in Unity for the file to open in an existing vim window, but instead it opens a new one.

To get around this I used various other SO answers to make a batch file and call vim using --remote-silent. This all works apart from vim acts like it wont allow remote commands to run on it.

Batch file:

@ECHO OFF
:Loop
IF "%1"=="" GOTO Continue
   start "" "C:\Program Files (x86)\Vim\vim73\gvim.exe" --remote-silent ":sp %1<CR>"
SHIFT
GOTO Loop
:Continue

It gives me

":sp C:\my\path\file.cs" [Permission Denied] Press enter or type command to continue

I tried removing the "%1" to check if it was the file that was giving the permission error, but no luck. The batch file runs via a shortcut that runs as administrator (nothing is ever simple in Windows)

Unity -> Shortcut -> Batch file -> gVim -> ":sp filename"

Any ideas why vim won't let this command run?

Can't seem to find any mention of permissions in vim help -remote files or anyone else seeing this on google.

Thanks.

*Edit 1 Looks like something weird si going on, if I do :ls I see this in my buffer list

2 %a=  ":sp C:\My\file\path.cs" line 1

Like its treating the whole command as the file path or something?

Martin Lyne
  • 3,157
  • 2
  • 22
  • 28

2 Answers2

2

--remote-silent takes a file list, not Ex commands (well, you can pass one via +{cmd} before the files); that's why Vim interprets your command as a (non-existing) file.

Using --remote-send is the correct approach; like in the help examples, you should prepend <C-\><C-N> to ensure that the remote Vim is in normal mode (otherwise, if you've left it in insert mode, the commands would be inserted literally!)

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
0

I solved this myself after spotting the buffer issue.

I changed my batch to the following:

@ECHO OFF
:Loop
IF "%1"=="" GOTO Continue
   start "" "C:\Program Files (x86)\Vim\vim73\gvim.exe" --remote-send ":sp %1<CR>"
SHIFT
GOTO Loop
:Continue

Looks like --remote-silent doesn't do what I thought it did.

I also added set shortmess=aoOtI to my vimrc to stop it prompting me.

Martin Lyne
  • 3,157
  • 2
  • 22
  • 28