Vim Tips Wiki
Register
(Change <tt> to <code>, perhaps also minor tweak.)
(Merged Content into Tip1440)
Line 1: Line 1:
{{Duplicate|1440}}
+
{{Merged|1440}}
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=1225
 
|id=1225

Revision as of 16:02, 28 August 2012

Obsolete tip

This tip has been merged into another tip.
See VimTip1440 for the current tip.

Please do not edit this tip, and do not edit the discussion page.
If anything needs to be improved, please fix VimTip1440.


Tip 1225 Printable Monobook Previous Next

created 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.

WARNING: Editing your Windows registry may cause unintended side effects that render your system inoperable. Although this tip has worked in the past for some people, there is no guarantee that it will work for you. Use with caution, and at your own risk.

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.

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.


The above suggestion "Another solution is to use autocmd..." made my 'Diff with Vim' right-click menu option not work properly. The solution for that is to allow the command only when in DIFF mode (&diff==0). Paste the following lines of code in the _vimrc file:

if (&diff==0)
    :autocmd BufReadPost * tab ball
endif

The command above allows the following two-fold functionality when 2 files are selected (using Ctrl key) and right-click options menu opens:

  1. clicking 'Open with single Vim' opens single Vim Window, each file is in its own tab
  2. clicking 'Diff with Vim' opens single Vim Window, DIFFing both files

The benefit of this approach is that there is no need to play with the registry files.