Movatterモバイル変換


[0]ホーム

URL:


Quick links:help overview ·quick reference ·user manual toc ·reference manual toc·faq
Go to keyword (shortcut:k)
Site search (shortcut:s)
if_ole.txt  ForVim version 9.2.  Last change: 2026 Feb 14VIM REFERENCE MANUAL  by Paul MooreThe OLEInterface to Vimole-interface1. Activationole-activation2. Methodsole-methods3. The "normal" commandole-normal4. Registrationole-registration5. MSVisual Studio integrationMSVisualStudio{only available when compiled with the+ole feature.  Seesrc/if_ole.INSTALL}An alternativeis using theclient-server communicationclientserver.==============================================================================1. Activationole-activationVim actsas an OLE automation server, accessible from any automation client,for example,Visual Basic, Python, or Perl.  The Vim application "name" (its"ProgID", in OLE terminology)is "Vim.Application".Hence, in order to starta Vim instance (or connect to an already runninginstance), code similar to the following should be used:[Visual Basic]Dim Vim As ObjectSet Vim = CreateObject("Vim.Application")[Python]from win32com.client.dynamic import Dispatchvim = Dispatch('Vim.Application')[Perl]use Win32::OLE;$vim = new Win32::OLE 'Vim.Application';[C#]// Add a reference to Vim in your project.// Choose the COM tab.// Select "Vim Ole Interface 1.1 Type Library"Vim.Vim vimobj = new Vim.Vim();Vim does not support actingasa "hidden" OLE server, like some other OLEAutomation servers.  Whena client starts up an instance of Vim, that instanceis immediately visible.  Simply closing the OLE connection to the Vim instanceis not enough to shut down the Vim instance-itis necessary to explicitlyexecutea quit command (for example, :qa!, :wqa).==============================================================================2. Methodsole-methodsVim exposes four methods for use by clients.ole-sendkeysSendKeys(keys)Executea series of keys.Thismethod takesa single parameter, whichisastring of keystrokes.  Thesekeystrokes are executed exactlyas if they had been typed inat the keyboard.Special keys can be given using their <..> names,as for the right hand sideofa mapping.Note: Execution of theEx "normal" commandis not supported-see belowole-normal.Examples (Visual Basic syntax)Vim.SendKeys "ihello<Esc>"Vim.SendKeys "ma1GV4jy`a"These examples assume that Vim starts inNormal mode.  To forceNormal mode,start the key sequence withCTRL-\CTRL-Nas inVim.SendKeys "<C-\><C-N>ihello<Esc>"CTRL-\CTRL-N returns Vim toNormal mode, when inInsert orCommand-line mode.Note that this doesn't work halfwaya Vim commandole-evalEval(expr)Evaluate an expression.Thismethod takesa single parameter, whichis anexpression in Vim's normalformat (seeexpression).  It returnsa string, whichis the result ofevaluating the expression.AListis turned intoastring by joining theitems andinserting line breaks.Examples (Visual Basic syntax)Line20 = Vim.Eval("getline(20)")Twelve = Vim.Eval("6 + 6")' Note this is a STRINGFont = Vim.Eval("&guifont")ole-setforegroundSetForeground()Make the Vimwindow come to the foregroundThismethod takes no arguments.  No valueis returned.Example (Visual Basic syntax)Vim.SetForegroundole-gethwndGetHwnd()Return the handle of the Vim window.Thismethod takes no arguments.  It returns the hwnd of the main Vimwindow.You can use this if you arewriting something which needs to manipulate theVim window, or to trackit in the z-order, etc.Example (Visual Basic syntax)Vim_Hwnd = Vim.GetHwnd==============================================================================3. The "normal" commandole-normalDue to the way Vim processes OLE Automation commands, combined with themethodof implementation of theEx command :normal,itis not possible to execute the:normal command via OLE automation.  Any attempt todo so will fail, probablyharmlessly, although possibly in unpredictable ways.Thereis currently no practical way to trap this situation, and usersmustsimply be aware of the limitation.==============================================================================4. Registrationole-registrationE243Before Vim will actas an OLE server,itmust be registered in the systemregistry.  In order todo this, Vim should be run witha single parameter of"-register".-registergvim -registerIfgvim with OLE supportis run and notices that no Vim OLE server has beenregistered,it will presentadialog and offers you the choice to register byclicking "Yes".In some situations registeringis not possible.  This happens when theregistryis not writable.  If you run into this problem you need to rungvimas "Administrator".Once vimis registered, the application pathis stored in the registry.Before moving, deleting, or upgrading Vim, the registry entries should beremoved using the "-unregister" switch.-unregistergvim -unregisterThe OLE mechanism will use the first registered Vimit finds.  Ifa Vimisalready running, this one will be used.  If you want to have (several) Vimsessions open that should not react to OLE commands, use the non-OLE version,andputit ina different directory.  The OLE version should then beput inadirectory thatis not in your normal path, so that typing "gvim" will startthe non-OLE version.-silentTo avoid the message box that pops up to report the result, prepend "-silent":gvim -silent -registergvim -silent -unregister==============================================================================5. MSVisual Studio integrationMSVisualStudioThe old "VisVim" integration was removed from Vim in patch 9.0.0698.Using Vim with Visual Studio .Net.Net studio has support for external editors.  Follow these directions:In .Net Studio choose from the menu Tools->External Tools...Add     Title- Vim     Command- c:\vim\vim63\gvim.exe     Arguments---servername VS_NET--remote-silent "+call cursor($(CurLine), $(CurCol))" $(ItemPath)     Init Dir- EmptyNow, when you opena file in .Net, you can choose from the .Net menu:Tools->VimThat will open the file in Vim.You can then add this external commandas an icon and placeit anywhere youlike.  You might also be able to set thisas your default editor.If you refine this further, please post back to the Vimmaillist so we havearecord of it.--servername VS_NETThis will createa new instance of vim called VS_NET.  So if you open multiplefiles from VS, they will use the same instance of Vim.  This allows you tohave multiple copies of Vim running, but you cancontrol which one has VSfiles in it.--remote-silent "+call cursor(10, 27)"- Places the cursor on line 10 column 27In Vim   :h --remote-silent for more details[.Net remarks provided by Dave Fishburn and Brian Sturk]============================================================================== vim:tw=78:ts=8:noet:ft=help:norl:

Quick links:help overview ·quick reference ·user manual toc ·reference manual toc·faq


[8]ページ先頭

©2009-2026 Movatter.jp