Open files in multiple tabs using the Windows Context Menu
From Vim Tips Wiki
[edit] Duplicate tip
This tip is very similar to the following:
These tips need to be merged – see the merge guidelines.
Tip 1225 Previous Next Created: May 10, 2006 Complexity: basic Author: K Winter Version: 7.0
Under Windows, the following allows you to open files in multiple tabs using the "Edit with Vim" Explorer context menu.
Save the following in a .reg text file:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Vim\Gvim] "path"="c:\\Program Files\\Vim\\vim70\\gvim.exe -p"
Merge this key into the registry by double clicking the file created above.
To restore the original settings, use the following .reg file:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Vim\Gvim] "path"="c:\\Program Files\\Vim\\vim70\\gvim.exe"
Note: The .reg files assume Vim 7.0 was installed in the default location – modify to suit your system.
[edit] Comments
Problem: This prevents the "Diff with Vim" command from working.
I'm using the --remote argument for opening files associated with Vim by default in the running instance in a new tab page.
[HKEY_CLASSES_ROOT\Applications\gvim.exe\shell\edit\command] @="C:\\Program Files\\Vim\\vim70\\gvim.exe --remote-tab-silent \"%1\""
See VimTip1314.
If you have set the default editor to gvim for your .c and .cpp files by using the context menu's Open With->Vim (and checking the 'Always use the selected program to open this kind of file'), then you need to modify the following registry keys to make sure every file is opened in a separate tab in the same instance of Vim.
For .c files: # HKCR\c_auto_file\shell\edit\command\Default -- change the value from C:\Program Files\Vim\vim70\gvim.exe "%1" to C:\Program Files\Vim\vim70\gvim.exe -p --remote-tab-silent "%1" # HKLM\software\classes\c_auto_file\shell\edit\command\Default -- change the value from C:\Program Files\Vim\vim70\gvim.exe "%1" to C:\Program Files\Vim\vim70\gvim.exe -p --remote-tab-silent "%1" Similarly for .cpp files: # HKCR\cpp_auto_file\shell\edit\command\Default -- change the value from C:\Program Files\Vim\vim70\gvim.exe "%1" to C:\Program Files\Vim\vim70\gvim.exe -p --remote-tab-silent "%1" # HKLM\software\classes\cpp_auto_file\shell\edit\command\Default -- change the value from C:\Program Files\Vim\vim70\gvim.exe "%1" to C:\Program Files\Vim\vim70\gvim.exe -p --remote-tab-silent "%1"
This way if you are in a habit of opening files from the command prompt, every filename you type on the command prompt will open the corresponding file in a separate tab in the same Vim instance.
The above works for Windows XP. For Windows 2003, setting HKCR\Applications\gvim.exe\shell\edit\command\(Default) to C:\Program Files\Vim\Vim70\gvim.exe -p --remote-tab-silent "%1" should do it when opening from command prompt or using context menu's Open With->Vim (and checking 'Always use the selected program...')
Another solution is to use autocmd: autocmd BufReadPost * tab ball
This will make sure every additional file that you open is opened in a tab. I like using this with the :tj command because I store each file name as a tag so I can easily jump to a file name by typing ":tj foo.php" and it will present me with a list of files named foo.php and then open my selection in a new tab. The :tabfind doesn't work well because it immediately opens the first file name that matches instead of presenting me with a list.
