1 *if_ole.txt* For Vim version 7.2b. Last change: 2007 May 10
4 VIM REFERENCE MANUAL by Paul Moore
7 The OLE Interface to Vim *ole-interface*
9 1. Activation |ole-activation|
10 2. Methods |ole-methods|
11 3. The "normal" command |ole-normal|
12 4. Registration |ole-registration|
13 5. MS Visual Studio integration |MSVisualStudio|
15 {Vi does not have any of these commands}
17 OLE is only available when compiled with the |+ole| feature. See
19 An alternative is using the client-server communication |clientserver|.
21 ==============================================================================
22 1. Activation *ole-activation*
24 Vim acts as an OLE automation server, accessible from any automation client,
25 for example, Visual Basic, Python, or Perl. The Vim application "name" (its
26 "ProgID", in OLE terminology) is "Vim.Application".
28 Hence, in order to start a Vim instance (or connect to an already running
29 instance), code similar to the following should be used:
33 Set Vim = CreateObject("Vim.Application")
36 from win32com.client.dynamic import Dispatch
37 vim = Dispatch('Vim.Application')
41 $vim = new Win32::OLE 'Vim.Application';
44 // Add a reference to VIM in your project.
45 // Choose the COM tab.
46 // Select "VIM Ole Interface 1.1 Type Library"
47 Vim.Vim vimobj = new Vim.Vim();
49 Vim does not support acting as a "hidden" OLE server, like some other OLE
50 Automation servers. When a client starts up an instance of Vim, that instance
51 is immediately visible. Simply closing the OLE connection to the Vim instance
52 is not enough to shut down the Vim instance - it is necessary to explicitly
53 execute a quit command (for example, :qa!, :wqa).
55 ==============================================================================
56 2. Methods *ole-methods*
58 Vim exposes four methods for use by clients.
61 SendKeys(keys) Execute a series of keys.
63 This method takes a single parameter, which is a string of keystrokes. These
64 keystrokes are executed exactly as if they had been types in at the keyboard.
65 Special keys can be given using their <..> names, as for the right hand side
66 of a mapping. Note: Execution of the Ex "normal" command is not supported -
67 see below |ole-normal|.
69 Examples (Visual Basic syntax) >
70 Vim.SendKeys "ihello<Esc>"
71 Vim.SendKeys "ma1GV4jy`a"
73 These examples assume that Vim starts in Normal mode. To force Normal mode,
74 start the key sequence with CTRL-\ CTRL-N as in >
76 Vim.SendKeys "<C-\><C-N>ihello<Esc>"
78 CTRL-\ CTRL-N returns Vim to Normal mode, when in Insert or Command-line mode.
79 Note that this doesn't work halfway a Vim command
82 Eval(expr) Evaluate an expression.
84 This method takes a single parameter, which is an expression in Vim's normal
85 format (see |expression|). It returns a string, which is the result of
86 evaluating the expression. A |List| is turned into a string by joining the
87 items and inserting line breaks.
89 Examples (Visual Basic syntax) >
90 Line20 = Vim.Eval("getline(20)")
91 Twelve = Vim.Eval("6 + 6") ' Note this is a STRING
92 Font = Vim.Eval("&guifont")
95 SetForeground() Make the Vim window come to the foreground
97 This method takes no arguments. No value is returned.
99 Example (Visual Basic syntax) >
104 GetHwnd() Return the handle of the Vim window.
106 This method takes no arguments. It returns the hwnd of the main Vimwindow.
107 You can use this if you are writing something which needs to manipulate the
108 Vim window, or to track it in the z-order, etc.
110 Example (Visual Basic syntax) >
111 Vim_Hwnd = Vim.GetHwnd
114 ==============================================================================
115 3. The "normal" command *ole-normal*
117 Due to the way Vim processes OLE Automation commands, combined with the method
118 of implementation of the ex command :normal, it is not possible to execute the
119 :normal command via OLE automation. Any attempt to do so will fail, probably
120 harmlessly, although possibly in unpredictable ways.
122 There is currently no practical way to trap this situation, and users must
123 simply be aware of the limitation.
124 ==============================================================================
125 4. Registration *ole-registration* *E243*
127 Before Vim will act as an OLE server, it must be registered in the system
128 registry. In order to do this, Vim should be run with a single parameter of
133 If gvim with OLE support is run and notices that no Vim OLE server has been
134 registered, it will present a dialog and offers you the choice to register by
137 In some situations registering is not possible. This happens when the
138 registry is not writable. If you run into this problem you need to run gvim
141 Once vim is registered, the application path is stored in the registry.
142 Before moving, deleting, or upgrading Vim, the registry entries should be
143 removed using the "-unregister" switch.
147 The OLE mechanism will use the first registered Vim it finds. If a Vim is
148 already running, this one will be used. If you want to have (several) Vim
149 sessions open that should not react to OLE commands, use the non-OLE version,
150 and put it in a different directory. The OLE version should then be put in a
151 directory that is not in your normal path, so that typing "gvim" will start
155 To avoid the message box that pops up to report the result, prepend "-silent":
157 gvim -silent -register
158 gvim -silent -unregister
160 ==============================================================================
161 5. MS Visual Studio integration *MSVisualStudio* *VisVim*
163 The OLE version can be used to run Vim as the editor in Microsoft Visual
164 Studio. This is called "VisVim". It is included in the archive that contains
165 the OLE version. The documentation can be found in the runtime directory, the
166 README_VisVim.txt file.
169 Using Vim with Visual Studio .Net~
171 With .Net you no longer really need VisVim, since .Net studio has support for
172 external editors. Follow these directions:
174 In .Net Studio choose from the menu Tools->External Tools...
177 Command - c:\vim\vim63\gvim.exe
178 Arguments - --servername VS_NET --remote-silent "+call cursor($(CurLine), $(CurCol))" $(ItemPath)
181 Now, when you open a file in .Net, you can choose from the .Net menu:
184 That will open the file in Vim.
185 You can then add this external command as an icon and place it anywhere you
186 like. You might also be able to set this as your default editor.
188 If you refine this further, please post back to the Vim maillist so we have a
192 This will create a new instance of vim called VS_NET. So if you open multiple
193 files from VS, they will use the same instance of Vim. This allows you to
194 have multiple copies of Vim running, but you can control which one has VS
197 --remote-silent "+call cursor(10, 27)"
198 - Places the cursor on line 10 column 27
200 :h --remote-silent for mor details
202 [.Net remarks provided by Dave Fishburn and Brian Sturk]
204 ==============================================================================
205 vim:tw=78:ts=8:ft=help:norl: