annotate runtime/doc/if_ole.txt @ 404:cf83dacfa25f v7.0105

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