How to open a file in an existing Vim instance instead of receiving an "existing swapfile" warning

I want Vim to reuse an existing instance if it exists. Typically, Vim issues a warning about an existing swap file. In particular, it is for switching between Vim and Visual Studio. (I know about ViEmu, but it does not work with Visual Studio Express.)

+6
vim visual-studio
source share
1 answer

Solution Poster:

Solution: There is a plugin in the standard Vim distribution: runtime / macros / editexisting.vim. Just copy it to the Vim plugin directory.

Additional Visual Studio Integration Details: Follow these steps to add Vim as an external tool and assign a convenient keyboard shortcut:

  • Title: Vim
  • Command: C: \ Program Files \ Vim \ vim70 \ gvim.exe
  • Arguments: + $ (CurLine) "$ (ItemPath)"
  • Start Directory: $ (SolutionDir)

Note. I use slightly different settings, so the cursor is set to a column from VS and centered in Vim:

  • Arguments: + "cursor ($ (CurLine), $ (CurCol))" + "normal zz" $ (ItemPath)
  • Start Directory: $ (FileDir)

Then set VS to automatically load chanages from Vim :

To use the two together effectively and make sure that .NET does not complain about file changes, goto Tools> Options> Environment> Documents and ensure these two options are checked: detect when the file is modified outside the environment. Changes to automatic loading (if not currently modified internally).

Finally, set Vim to automatically download changes made from VS :

: install autoread


My decision

Similar, but subtly fine: save it in a .settings file and import. Uses --servername and --remote-call to reuse an existing Vim adapted to the current solution.

 <UserSettings> <ApplicationIdentity version="8.0"/> <ToolsOptions/> <Category name="Environment_Group" RegisteredName="Environment_Group"> <Category name="Environment_ExternalTools" Category="{E8FAE9E8-FBA2-4474-B134-AB0FFCFB291D}" Package="{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}" RegisteredName="Environment_ExternalTools" PackageName="Visual Studio Environment Package"> <PropertyValue name="edit with v&amp;im.Command">gvim.exe</PropertyValue> <PropertyValue name="edit with v&amp;im.Arguments">--servername $(SolutionFileName) --remote-silent +"call cursor($(CurLine),$(CurCol))" "$(ItemFileName)$(ItemExt)"</PropertyValue> <PropertyValue name="edit with v&amp;im.InitialDirectory">$(ItemDir)</PropertyValue> <PropertyValue name="edit with v&amp;im.SourceKeyName"/> <PropertyValue name="edit with v&amp;im.UseOutputWindow">false</PropertyValue> <PropertyValue name="edit with v&amp;im.PromptForArguments">false</PropertyValue> <PropertyValue name="edit with v&amp;im.CloseOnExit">false</PropertyValue> <PropertyValue name="edit with v&amp;im.IsGUIapp">true</PropertyValue> <PropertyValue name="edit with v&amp;im.SaveAllDocs">true</PropertyValue> <PropertyValue name="edit with v&amp;im.UseTaskList">false</PropertyValue> <PropertyValue name="edit with v&amp;im.Unicode">false</PropertyValue> <PropertyValue name="edit with v&amp;im.Package">{00000000-0000-0000-0000-000000000000}</PropertyValue> <PropertyValue name="edit with v&amp;im.NameID">0</PropertyValue> </Category> </Category> </UserSettings> 
+6
source share

All Articles