
WINDOWS.txt

An ad-hoc compilation of tips specific to using Cream/Vim on the
Microsoft Windows platform. From the Cream for Vim project
(http://cream.sourceforge.net).

Compiler: Steve Hall  [ digitect dancingpaper com ]
Updated:  2007-01-17 08:14:53EST


**********************************************************************
DISCLAIMER

THESE TIPS ARE FOR ADVANCED  USERS  ONLY!  THEY  MODIFY  YOUR  WINDOWS
REGISTRY, SOMETHING THAT EVEN MICROSOFT HAS TROUBLE  DOING  CORRECTLY.
WE CAN PROVIDE ABSOLUTELY NO GUARANTEE THAT THEY WILL WORK AT ALL, AND
MAY EVEN COMPLETELY DESTROY YOUR ENTIRE SYSTEM AND DATA, AND  POSSIBLY
A FEW OTHERS NEAR BY. YOU USE  THESE  COMPLETELY  AT  YOUR  OWN  RISK!
**********************************************************************

Registry Backup {{{1
---------------------------------------------------------------------

You are advised to back up your registry before using any of the tools
in this file. Simply run "regedit" and use the File.Export item to
save a backup before proceeding. On Windows 95 (possibly 98-ME), you
can also copy the lines below into a file "regback.bat", drop it onto
your path (C:\WINDOWS works) and run it. 

----| regbak.bat |----------------------------------------------------
  @echo OFF
rem Saves copies of Windows system registry files.

rem change to Windows directory
   C:
   cd \WINDOWS

rem turn off hidden/read-only/system attribute
   attrib -h -r -s SYSTEM.DAT
   attrib -h -r -s USER.DAT

rem back up (up to 9 versions)
   if exist SYSTEM.DA8 copy SYSTEM.DA8 SYSTEM.DA9 /Y >nul
   if exist SYSTEM.DA7 copy SYSTEM.DA7 SYSTEM.DA8 /Y >nul
   if exist SYSTEM.DA6 copy SYSTEM.DA6 SYSTEM.DA7 /Y >nul
   if exist SYSTEM.DA5 copy SYSTEM.DA5 SYSTEM.DA6 /Y >nul
   if exist SYSTEM.DA4 copy SYSTEM.DA4 SYSTEM.DA5 /Y >nul
   if exist SYSTEM.DA3 copy SYSTEM.DA3 SYSTEM.DA4 /Y >nul
   if exist SYSTEM.DA2 copy SYSTEM.DA2 SYSTEM.DA3 /Y >nul
   if exist SYSTEM.DA1 copy SYSTEM.DA1 SYSTEM.DA2 /Y >nul
   copy SYSTEM.DAT SYSTEM.DA1 /Y >nul

   if exist USER.DA8 copy USER.DA8 USER.DA9 /Y >nul
   if exist USER.DA7 copy USER.DA7 USER.DA8 /Y >nul
   if exist USER.DA6 copy USER.DA6 USER.DA7 /Y >nul
   if exist USER.DA5 copy USER.DA5 USER.DA6 /Y >nul
   if exist USER.DA4 copy USER.DA4 USER.DA5 /Y >nul
   if exist USER.DA3 copy USER.DA3 USER.DA4 /Y >nul
   if exist USER.DA2 copy USER.DA2 USER.DA3 /Y >nul
   if exist USER.DA1 copy USER.DA1 USER.DA2 /Y >nul
   copy USER.DAT USER.DA1 /Y >nul

rem reinstate original attributes
   attrib +h +r +s SYSTEM.DAT
   attrib +h +r +s USER.DAT
---------------------------------------------------------------------

Sources {{{1
---------------------------------------------------------------------
o The vim mailing lists over a period of several years.
o Vim help document "gui_w32". (Specifically sections
  "win32-popup-menu", "install-registry" and "send-to-menu".)
o "Vim", Section 5 "Configuring Internet Explorer v5", by Freddy
  Vulto. http://home.wanadoo.nl/fvu/Projects/Vim/Web/vim.htm.
o Various mails to vim@vim.org list from Colin Keith, Pritesh Mistry,
  and Dan Sharp on Feb 1-2, 2003. ()

General Notes {{{1
---------------------------------------------------------------------
o Verify paths in all cases! We assume the path:

    C:\PROGRA~1\vim\vim70\gvim.exe

o Note that path backslashes must be doubled and that all paths must
  be double quoted to protect possible spaces in paths.
o You can define the character used for the shortcut by defining a
  name for the command and placing an ampersand ("&") before it in the
  name of the command. i.e "Edit with g&Vim".

1}}}
Default Vim Registry Entries
Main {{{1
---------------------------------------------------------------------

These are the default registry actions taken by Vim's install.exe and
uninstall.exe.

----| vim-registry-install.reg |--------------------------------------
REGEDIT4

; Source: Vim help (:help install-registry)
; Tested: 2003-03-05

[HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}]
@="Vim Shell Extension"
[HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}\InProcServer32]
; *** VERIFY PATH BELOW ***
@="C:\\Program Files\\vim\\vim70\\gvimext.dll"
"ThreadingModel"="Apartment"

[HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\gvim]
@="{51EEE242-AD87-11d3-9C1E-0090278BBD99}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved]
"{51EEE242-AD87-11d3-9C1E-0090278BBD99}"="Vim Shell Extension"

[HKEY_LOCAL_MACHINE\SOFTWARE\Vim]
[HKEY_LOCAL_MACHINE\SOFTWARE\Vim\Gvim]
; *** VERIFY PATH BELOW ***
"path"="C:\\Program Files\\vim\\vim70\\gvim.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Vim]
"DisplayName"="Vim (self-installing)"
; *** VERIFY PATH BELOW ***
"UninstallString"="C:\\Program Files\\vim\\vim70\\uninstall-gui.exe"
----------------------------------------------------------------------

----| vim-registry-uninstall.reg |------------------------------------
REGEDIT4

; Tested:

[-HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}\InProcServer32]
[-HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}]

[-HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\gvim]

[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved]

[-HKEY_LOCAL_MACHINE\SOFTWARE\Vim\Gvim]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Vim]

[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Vim]
----------------------------------------------------------------------

Context Sensitive "Edit with Vim..." Menu {{{1
---------------------------------------------------------------------

o Create a Vim entry in the right-click menu that is context
  sensitive. (It will present different options depending on the
  file(s) selected.)
o These require the use of the gvimext.dll that is distributed with
  Vim.
o Edit the paths below to match your actual location of gvimext.dll.
o These are redundant with Vim's install.exe default behavior (above)!


----| context-sensitive-menu-install.reg |----------------------------
REGEDIT4

; Tested: 2003-03-18

[HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}]
@="Vim Shell Extension"
[HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}\InProcServer32]
@="C:\\PROGRA~1\\vim\\vim70\\gvimext.dll"
"ThreadingModel"="Apartment"

[HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\gvim]
@="{51EEE242-AD87-11d3-9C1E-0090278BBD99}"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved]
"{51EEE242-AD87-11d3-9C1E-0090278BBD99}"="Vim Shell Extension"

; Not sure if these are required, but won't hurt.
[HKEY_LOCAL_MACHINE\SOFTWARE\Vim]
[HKEY_LOCAL_MACHINE\SOFTWARE\Vim\Gvim]
"path"="C:\\PROGRA~1\\vim\\vim70\\gvim.exe"
----------------------------------------------------------------------

----| context-sensitive-menu-uninstall.reg |--------------------------
REGEDIT4

; Tested: 2003-03-18

[-HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}\InProcServer32]
[-HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}]

[-HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\gvim ]

; Hmm... what if these involve more?
[-HKEY_LOCAL_MACHINE\SOFTWARE\Vim\Gvim]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Vim]
----------------------------------------------------------------------

1}}}

creamopen.vbs

Most default registry tips for Vim rely on passing the filename as an
argument to Vim or some part of the operating system. Unfortunately,
Windows has historically promoted the use of spaces within paths and
filenames, meaning that when a single path-filename is passed to Vim
or the OS, each section between spaces is interpreted as a *separate*
path-filename. So when you thought you were opening:

  1. C:\Documents and Settings\me\Desktop\My File.txt

you were actually opening four buffers called:

  1. C:\Documents 
  2. and 
  3. Settings\me\Desktop\My 
  4. File.txt

To resolve this, an Visual Basic Script (VBS) is created to
concatenate these parts back together and then pass them to Cream/Vim
as a single quoted argument.

ALL TECHNIQUES BELOW RELY ON THIS SCRIPT!

creamopen.vbs {{{1
---------------------------------------------------------------------

----| creamopen.vbs |-----------------------------------------
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Start Cream/Vim, combining multiple arguments to single file
' argument.
'
' Sources:
' * Original script:
'     http://home.wanadoo.nl/fvu/Projects/Vim/Web/vim.htm
'
' * VimOnline Tip #118, by Freddy Vulto:
'     http://vim.sourceforge.net/tip_view.php?tip_id=118
'
' * VimOnline Tip #190, by Hal Atherton, tested on WinXP and
'   IE6: 
'     http://vim.sourceforge.net/tip_view.php?tip_id=190
'
' * VimOnline Tip #134, by Eric Lee, tested on WinXP and
'     http://vim.sourceforge.net/tip_view.php?tip_id=134
'
' Orig. Name:   gVim.vbs
' Orig. Author: Freddy Vulto <fvu(at)fvu.myweb.nl>
' Modified by:  Steve Hall <digitect dancingpaper com>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Make variable declaration mandatory
option explicit

dim oWShell, sArg, sFile

' Create script object
set oWShell = CreateObject("wscript.shell")
' Loop through arguments
for each sArg in wscript.arguments
' Add argument to filename
sFile = sFile & sArg & " "
next
' Remove excess space
sFile = Trim(sFile)
' Run Vim with file argument.
oWShell.Run _
"""C:\PROGRA~1\vim\vim70\gvim.exe""" & _
"-U NONE -u C:\PROGRA~1\vim\vim70\cream\creamrc " & _
"""" & sFile & """"

' Destroy script object
set oWShell = NOTHING
---------------------------------------------------------------------

1}}}
creamopen.vbs Actions
Context Insensitive "Edit with Cream/Vim..." Menu {{{1
---------------------------------------------------------------------

If you always want "Edit with Cream/Vim" to appear in the context
menu, you can use these.

----| context-insensitive-menu-install.reg |--------------------------
REGEDIT4

; Source: Pritesh Mistry, 2/4/2003 1:16 AM mail to vim@vim.org list.
; Tested: 2003-03-18

[HKEY_CLASSES_ROOT\*\Shell\Cream]
@="Edit With Cream/&Vim"

[HKEY_CLASSES_ROOT\*\Shell\Cream\Command]
;@="C:\\PROGRA~1\\vim\\vim70\\cream\\creamopen.vbs"
;@="C:\\PROGRA~1\\vim\\vim70\\gvim.exe"
;"$\"$0\gvim.exe$\" $\"-u$\" $\"$0\cream\creamrc$\" $\"%1$\""

----------------------------------------------------------------------

----| context-insensitive-menu-uninstall.reg |------------------------
REGEDIT4

; Tested: 2003-03-18

[-HKEY_CLASSES_ROOT\*\Shell\Cream\Command]
[-HKEY_CLASSES_ROOT\*\Shell\Cream]
----------------------------------------------------------------------

Open Unassociated MIME Types {{{1
---------------------------------------------------------------------

Windows prompts the user to select a program to open unassociated file
types. To automatically open these with Vim without any prompting.


----| unassociated-MIME-WinNT-install.reg |---------------------------
REGEDIT4
; Source: VimOnline Tip #185, by Leif Wickland
;         http://vim.sourceforge.net/tip_view.php?tip_id=185
;
; o WinNT only!

; Tested:

[HKEY_CLASSES_ROOT\Unknown\shell\Open\Command]
@="C:\\PROGRA~1\\vim\\vim70\\cream\\creamopen.vbs"
----------------------------------------------------------------------

----| unassociated-MIME-WinNT-uninstall.reg |-------------------------
REGEDIT4

; o WinNT only!

; Tested:

[-HKEY_CLASSES_ROOT\Unknown\shell\Open\Command]
----------------------------------------------------------------------


----| unassociated-MIME-Win2K-install.reg |-------------------------
REGEDIT4
; Source: VimOnline Tip #185, comment by Klaus Horsten
;         http://vim.sourceforge.net/tip_view.php?tip_id=185
;
; o WARNING! This tip appears to tamper with the "Open With..." menu
;   and in some cases remove it. We can't recommend using it.
; o Win2K only!

; Tested:
; o Win2K (David Menuhin)

[HKEY_CLASSES_ROOT\Unknown\shell\openas\command]
@="C:\\PROGRA~1\\vim\\vim70\\cream\\creamopen.vbs"
----------------------------------------------------------------------

----| unassociated-MIME-Win2K-uninstall.reg |.......................
REGEDIT4

; * Win2K only!

; Tested:

[-HKEY_CLASSES_ROOT\Unknown\shell\openas\command]
----------------------------------------------------------------------


Send To {{{1
---------------------------------------------------------------------

Simply copy a shortcut of creamopen.vbs into your profile's SendTo folder.
In WinXP, this is "C:\Documents and Settings\[username]\SendTo".
In Win95, this is "C:\Windows\SendTo"
In WinNT, this might be somewhere in between. ;)

(See also :help send-to-menu in the Vim on-line help.)

Internet Explorer, Edit With Vim {{{1
---------------------------------------------------------------------

You can use Vim to edit local files browsed with Internet Explorer.
Just use the registry entries below and restart IE. Then use the
Alt+F,D keyboard accelerator for fast editing.

----| ie-editor-install.reg |-----------------------------------------
REGEDIT4

; relies on creamopen.vbs
;
; Do NOT modify ".html" list, registry for ".htm" accomplishes both.
;
; Tested:
; o Win2K (David Menuhin)

[HKEY_CLASSES_ROOT\.htm\OpenWithList\Cream\shell\edit\command] 
@="C:\\PROGRA~1\\vim\\vim70\\cream\\creamopen.vbs"
----------------------------------------------------------------------

----| ie-editor-uninstall.reg |---------------------------------------
REGEDIT4

; Tested:

[-HKEY_CLASSES_ROOT\.htm\OpenWithList\Cream]
[-HKEY_CLASSES_ROOT\.html\OpenWithList\Cream]
----------------------------------------------------------------------

Internet Explorer, View Source {{{1
---------------------------------------------------------------------

To change the default View.Source editor for Internet Explorer, you
can use the following method. (Note that the previous information for
changing Internet Explorer's "Edit with Vim" entry is more efficient
and doesn't require a VBS referer as this tip does. It also has a
slightly more reachable Alt+F,D accelerator key combination as opposed
to the View.Source Alt+V,C.)


----| ie-viewsource.reg |---------------------------------------------
REGEDIT4

; relies on creamopen.vbs!

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor] 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name] 
@="C:\\PROGRA~1\\vim\\vim70\\cream\\creamopen.vbs" 
----------------------------------------------------------------------

----| ie-viewsource-uninstall.reg |-----------------------------------
REGEDIT4

[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name] 
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\View Source Editor]
----------------------------------------------------------------------

Cream the default .txt application {{{1
---------------------------------------------------------------------

This might be a better way to set the open action for a MIME type.
Except that it doesn't appear to work in practice. The vbs runline is
effective at the command line, but there's still some sort of quoting
issue.

----| default-text-app.reg |-----------------------------------------
REGEDIT4

; relies on creamopen.vbs

[HKEY_CLASSES_ROOT\txtfile\shell\open\command]
@="C:\\PROGRA~1\\vim\\vim70\\cream\\creamopen.vbs"
----------------------------------------------------------------------

----| default-text-app-uninstall.reg |-----------------------------------
REGEDIT4

; UNTESTED

[-HKEY_CLASSES_ROOT\txtfile\shell\open\command]
----------------------------------------------------------------------

1}}}
 vim:foldmethod=marker
