4

I wanted to know if there might be a way to open a text file in an existing console vim. This would really help my current workflow. I default to sublime when opening things from the desktop because I haven't been able to find a good way to do this. Also, I do know about gvim, but I'm not a big fan of it.

Thanks!

  • Do you want a mouse solution or is a command line solution okay? Also, how do you want the new file to open? In a new tab? New buffer? Replace the current file? – James Jun 11 '16 at 18:31
6

To do this from the command line is actually very easy. First, open an instance of vim. Then, in a new cmd, type:

vim --remote-silent +e filename

You could also do

vim --remote-silent +split filename
vim --remote-silent +tabedit filename

Depending on the behavior you want.

However, running stuff in the command line isn't always the most convenient, especially in windows. To add this to the context menu, e.g. right click a file then have this option, do the following:

  1. Make a file with a .reg extension, and save this to it:

    Windows Registry Editor Version 5.00
    [HKEY_CLASSES_ROOT\*\Shell\vimEdit]
    @="Edit in existing vim"
    [HKEY_CLASSES_ROOT\*\Shell\vimEdit\command]
    @="\"C:\\Program Files (x86)\\Vim\\vim74\\vim.exe\" --remote-tab-silent +edit %1"
    
  2. Double click this file. This will add "Edit in existing vim" to your context menu. Now, you can right click on a file, and it will open in a new vim if you don't have one open, or in a new tab on an existing vim if you don't.

If you don't want this in a new tab, just change --remote-tab-silent to --remote-silent

| improve this answer | |
  • Thanks! The %1 parameter should be quoted to allow for filenames with spaces: @="\"C:\\Program Files (x86)\\Vim\\vim80\\gvim.exe\" --remote-tab-silent +edit \"%1\"" – Crosbie Feb 7 '17 at 18:55

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.