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!

1
  • 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?
    – DJMcMayhem
    Commented Jun 11, 2016 at 18:31

1 Answer 1

7

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

1
  • 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
    Commented Feb 7, 2017 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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