blob: eff7bb2e785234fdf088494bdadec1f9cfc6d480 [file] [log] [blame]
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001*if_ole.txt* For Vim version 7.0aa. Last change: 2006 Mar 06
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Paul Moore
5
6
7The OLE Interface to Vim *ole-interface*
8
91. Activation |ole-activation|
102. Methods |ole-methods|
113. The "normal" command |ole-normal|
124. Registration |ole-registration|
135. MS Visual Studio integration |MSVisualStudio|
14
15{Vi does not have any of these commands}
16
17OLE is only available when compiled with the |+ole| feature. See
18src/if_ole.INSTALL.
19An alternative is using the client-server communication |clientserver|.
20
21==============================================================================
221. Activation *ole-activation*
23
24Vim acts as an OLE automation server, accessible from any automation client,
Bram Moolenaar402d2fe2005-04-15 21:00:38 +000025for example, Visual Basic, Python, or Perl. The Vim application "name" (its
Bram Moolenaar071d4272004-06-13 20:20:40 +000026"ProgID", in OLE terminology) is "Vim.Application".
27
28Hence, in order to start a Vim instance (or connect to an already running
29instance), code similar to the following should be used:
30
31[Visual Basic] >
32 Dim Vim As Object
33 Set Vim = CreateObject("Vim.Application")
34
35[Python] >
36 from win32com.client.dynamic import Dispatch
37 vim = Dispatch('Vim.Application')
38
39[Perl] >
40 use Win32::OLE;
41 $vim = new Win32::OLE 'Vim.Application';
42
43Vim does not support acting as a "hidden" OLE server, like some other OLE
Bram Moolenaar402d2fe2005-04-15 21:00:38 +000044Automation servers. When a client starts up an instance of Vim, that instance
45is immediately visible. Simply closing the OLE connection to the Vim instance
Bram Moolenaar071d4272004-06-13 20:20:40 +000046is not enough to shut down the Vim instance - it is necessary to explicitly
47execute a quit command (for example, :qa!, :wqa).
48
49==============================================================================
502. Methods *ole-methods*
51
52Vim exposes four methods for use by clients.
53
54 *ole-sendkeys*
55SendKeys(keys) Execute a series of keys.
56
Bram Moolenaar402d2fe2005-04-15 21:00:38 +000057This method takes a single parameter, which is a string of keystrokes. These
Bram Moolenaar071d4272004-06-13 20:20:40 +000058keystrokes are executed exactly as if they had been types in at the keyboard.
59Special keys can be given using their <..> names, as for the right hand side
Bram Moolenaar402d2fe2005-04-15 21:00:38 +000060of a mapping. Note: Execution of the Ex "normal" command is not supported -
Bram Moolenaar071d4272004-06-13 20:20:40 +000061see below |ole-normal|.
62
63Examples (Visual Basic syntax) >
64 Vim.SendKeys "ihello<Esc>"
65 Vim.SendKeys "ma1GV4jy`a"
66
Bram Moolenaar402d2fe2005-04-15 21:00:38 +000067These examples assume that Vim starts in Normal mode. To force Normal mode,
Bram Moolenaar071d4272004-06-13 20:20:40 +000068start the key sequence with CTRL-\ CTRL-N as in >
69
70 Vim.SendKeys "<C-\><C-N>ihello<Esc>"
71
72CTRL-\ CTRL-N returns Vim to Normal mode, when in Insert or Command-line mode.
73Note that this doesn't work halfway a Vim command
74
75 *ole-eval*
76Eval(expr) Evaluate an expression.
77
78This method takes a single parameter, which is an expression in Vim's normal
79format (see |expression|). It returns a string, which is the result of
Bram Moolenaar362e1a32006-03-06 23:29:24 +000080evaluating the expression. A |List| is turned into a string by joining the
81items and inserting line breaks.
Bram Moolenaar071d4272004-06-13 20:20:40 +000082
83Examples (Visual Basic syntax) >
84 Line20 = Vim.Eval("getline(20)")
85 Twelve = Vim.Eval("6 + 6") ' Note this is a STRING
86 Font = Vim.Eval("&guifont")
87<
88 *ole-setforeground*
89SetForeground() Make the Vim window come to the foreground
90
91This method takes no arguments. No value is returned.
92
93Example (Visual Basic syntax) >
94 Vim.SetForeground
95<
96
97 *ole-gethwnd*
98GetHwnd() Return the handle of the Vim window.
99
100This method takes no arguments. It returns the hwnd of the main Vimwindow.
101You can use this if you are writing something which needs to manipulate the
102Vim window, or to track it in the z-order, etc.
103
104Example (Visual Basic syntax) >
105 Vim_Hwnd = Vim.GetHwnd
106<
107
108==============================================================================
1093. The "normal" command *ole-normal*
110
111Due to the way Vim processes OLE Automation commands, combined with the method
112of implementation of the ex command :normal, it is not possible to execute the
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000113:normal command via OLE automation. Any attempt to do so will fail, probably
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114harmlessly, although possibly in unpredictable ways.
115
116There is currently no practical way to trap this situation, and users must
117simply be aware of the limitation.
118==============================================================================
1194. Registration *ole-registration* *E243*
120
121Before Vim will act as an OLE server, it must be registered in the system
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000122registry. In order to do this, Vim should be run with a single parameter of
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123"-register".
124 *-register* >
125 gvim -register
126
127If gvim with OLE support is run and notices that no Vim OLE server has been
128registered, it will present a dialog and offers you the choice to register by
129clicking "Yes".
130
131In some situations registering is not possible. This happens when the
132registry is not writable. If you run into this problem you need to run gvim
133as "Administrator".
134
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000135Once vim is registered, the application path is stored in the registry.
136Before moving, deleting, or upgrading Vim, the registry entries should be
137removed using the "-unregister" switch.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138 *-unregister* >
139 gvim -unregister
140
141The OLE mechanism will use the first registered Vim it finds. If a Vim is
142already running, this one will be used. If you want to have (several) Vim
143sessions open that should not react to OLE commands, use the non-OLE version,
144and put it in a different directory. The OLE version should then be put in a
145directory that is not in your normal path, so that typing "gvim" will start
146the non-OLE version.
147
148 *-silent*
149To avoid the message box that pops up to report the result, prepend "-silent":
150>
151 gvim -silent -register
152 gvim -silent -unregister
153
154==============================================================================
1555. MS Visual Studio integration *MSVisualStudio* *VisVim*
156
157The OLE version can be used to run Vim as the editor in Microsoft Visual
158Studio. This is called "VisVim". It is included in the archive that contains
159the OLE version. The documentation can be found in the runtime directory, the
160README_VisVim.txt file.
161
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000162
163Using Vim with Visual Studio .Net~
164
165With .Net you no longer really need VisVim, since .Net studio has support for
166external editors. Follow these directions:
167
168In .Net Studio choose from the menu Tools->External Tools...
169Add
170 Title - Vim
171 Command - c:\vim\vim63\gvim.exe
172 Arguments - --servername VS_NET --remote-silent "+call cursor($(CurLine), $(CurCol))" $(ItemPath)
173 Init Dir - Empty
174
175Now, when you open a file in .Net, you can choose from the .Net menu:
176Tools->Vim
177
178That will open the file in Vim.
179You can then add this external command as an icon and place it anywhere you
180like. You might also be able to set this as your default editor.
181
182If you refine this further, please post back to the Vim maillist so we have a
183record of it.
184
185--servername VS_NET
186This will create a new instance of vim called VS_NET. So if you open multiple
187files from VS, they will use the same instance of Vim. This allows you to
188have multiple copies of Vim running, but you can control which one has VS
189files in it.
190
191--remote-silent "+call cursor(10, 27)"
192 - Places the cursor on line 10 column 27
193In Vim >
194 :h --remote-silent for mor details
195
196[.Net remarks provided by Dave Fishburn and Brian Sturk]
197
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198==============================================================================
199 vim:tw=78:ts=8:ft=help:norl: