Vim everywhere

With a (for private use free) program called shortcut you're able to define a shortcut-keystroke to launch Vim from every windows application, edit the text there and jump back to the original application with another keystroke. If you prefer to use another editor you can adapt the shortcut-macros to work with every other win32 editor you like.

How to use Vim as an external editor from every windows application

The workflow

  1. In every edit-window in any windows 32 application you're using use the same shortcut-keystroke (customisable of course) to launch the current text window into Vim. Edit the text in Vim and be happy.
  2. Use another shortcut-keystroke to paste the changed text back to the original application. You have to be in insert mode to call that shortcut-keystroke (more about that later). The not longer used buffer in Vim is closed automatic. I've chosen not to close Vim, but you can do easily if you prefer that.

Installation

Requirements

Steps

I assume you're new to shortcut. If not you surely know what to do with the macros :-)
  1. Put (G)Vim into your path: "My Computer- Properties - Advanced - Environment Variables" (on a german system: Systemsteuerung - System - Erweitert - Umgebungsvariablen). Edit the PATH variable there and add the path to your GVim.exe (use a ; to separate several paths). Alternative you can type the path to your gvim.exe in the shortcut macro (see the comments in the macro).
  2. Depending which version you've chosen to download, either install shortcut with the setup file or unzip it to a directory you like.
  3. Copy the shortcut.ini file from vimall.zip over the default shorcut.ini file. Now you're ready to run shortcut.
  4. Additional make a link to shorcut.exe in your autostart folder.
  5. English speaking persons: When shortcut is running, doubleclick on the shortcut-icon in the task-bar. Choose the tab "Allgemein" and toggle "Lokalisierung" from "Deutsch" to "English". The GUI will switch to english. Unfortunately the help file is german only.

Shortcut

It's time for a quick oversight over the possibilities shortcut offers:

Usage

In the original application

To launch the text, from the edit-window of any application you're using, in GVim just type the defined shortcut. On my german keyboard I have defined

    #vim

to start editing the current text-window in GVim. The settings in the sample shortcut.ini file make sure that this shortcut-text #vim is expanded automatic. I have set the time span to a very large value, so that you'll see the effect easy. For real world usage I suggest to try out a smaller time span. I type pretty fast and have the following settings: "Expand shortcuts when no keypress for 0_ms" and "Maximum time between key presses for automatic expansion of shortcuts: 500_ms". You find those settings on the tab "Control".

In Vim and back...

Edit the text in Vim to your liking and when you decide to jump back to the original application use another keyboard shortcut you have defined. As an example I have defined

    #vz

(vim zurück (back)) which copies the current buffer in Vim to the clipboard, closes the buffer and then jumps back to the original application where the changed text is pasted back. Note that you have to be in insert mode in Vim, otherwise the normal mode command # will start a backward search for the word under the cursor. If you want to make sure that the shortcut macro will not conflict with a Vim command (in normal or even visual mode) I suggest to define another shortcut. On english keyboards a macro preceded with a backslash might be the best way to go, as the backslash is the only char which has no command meaning in Vim's normal or visual mode.

Alternative shortcuts

Still another option is to use the ability of shortcut to invoke an application or a macro with a short keyboard sequence (shortcut) after you've pressed a hotkey which is user defined. As an example I have defined the hotkey CTRL-# (on a german keyboard again) to expand a shortcut. This can be used when you've typed the shortcut slower then the time for automatic expansion. This hotkey is also used to tell shortcut that the following keystrokes should be recognized to launch an application (or even a macro), look at the "Applications" tab in shortcut.

CTRL-# is not a Vim command and therefore can be savely used as the shortcut expansion hotkey. In addition this shortcut can be used in Vim regardless of the mode Vim is just in. Press CTRL-# and then type

    vi

to launch Vim for the current text window and in Vim after pressing using the defined hotkey (in my example CTRL-#) type

    va

to jump back to the beginning (german: Anfang). The shortcuts in the application tab must be different then those chosen as a shortcut macro.

If you take care that the chosen shortcut will not conflict with Vim commands I see no real advantage in the first or this solution. Choose whichever suits your working style better.

Implementation

The macros are commented. I have tried to explain every step which is done. You can modify them if you need/want to. One example could be that you need to increase the wait commands on slower computers. On my Duron 800 I needed less wait time compared to my Celeron 433.

Here's an oversight over the special chars you can use inside a macro:

    \t        tabstop                   \p        page up
    \m        newline                   \v        page down
    \n        newline                   \e        end
    \b        backspace                 \x        delete
    \d        arrow down                \f2..24   function keys F1 to F24
    \u        arrow up                  \@        Alt
    \l        arrow left                \^        Ctrl
    \r        arrow right               \~        Shift
    \h        Pos1 (Home)               \-        Escape
    \i        insert                    \\        Backslash
    \j        carriage return (^j)      \[..]     any ANSI code

Further info is found in the german help file of shortcut.

Remarks

The solution takes care...

You have to take care...

Like the macro is written now, pasting the text back into the original application assumes that you've not changed to another (this means new single document interface) window in the original application and that the original text is still marked. If that's not the case you'd have to take care of that in the shortcut macro.

Note that shortcut can not distinguish a single window from one application which was loaded with different texts (like one edit-window in the e-mail application), but it does know several windows which are opened at the same time, even from one application. So SDI applications can be used, MDI applications won't recognize the different "hidden" windows and the text will always be pasted "back" to the current MDI window, which might or might not be what you want.

In the macro #vz in the given example shortcut.ini I have used the sequence CTRL-v to paste the text back to the original application. The other option would have been to use to use the command

    clip()

to paste the text from the clipboard to the application window. Using clip() will work in every application, but the text is pasted charwise. For long texts this might be rather slow. As every application I use has the control sequence CTRL-v to paste text from the clipboard I have chosen this way. This has the advantage that it's faster then using clip(), but may not work, when CTRL-v is not defined in the applications you're using. This is unlikely, but in case that you can't work with CTRL-v, just use the command clip() instead. I've already made a remark in the comments of the macro #vz where it needs to be changed then.

More then one external text buffer

At the moment the macro does not allow to edit multiple texts outside of the original application. The macro is not (yet) able to recognize from the Vim buffer itself where it comes from, so you have to define several "edit-in-Vim" and "go-back" shortcuts and choose the right one yourself to jump back to the corresponding application. Change the name for the global variable HERKUNFT (for example HERKUNFT2...) and define extra keyboard shortcuts for the new macros.

If I find myself editing more then two files at the same time often, then I'll try to implement that the handle info is tied to the Vim buffer. I'm pretty confident this can be done. One idea is to write the handle number into the vim buffer (first or last line) and use that later to go back to the original application with one universal "go-back" shortcut. Of course the handle info would get extracted then, as it's not longer needed/wanted. A more elegant solution would be to use an extra file which remembers which Vim buffer belongs to which application window.

Formatting options

The text is just pasted into Vim. The macro is not used to reformat (for e-mails for example) the text or to do other things. I'd suggest to add a :source mymacro.vim command to the end of the shortcut-macro to load a vim macro if you like that. Of course you also could hardwire your commands to format the text in the shortcut macro, but using Vim macros might turn out to be easier to maintain. If you want different actions to happen when you edit a file outside of the original application in Vim, you can pass arguments to the shortcut-keyboard-macro which do specific things. This is not implemented as I don't need it right now. But this can be done with the macro language from shortcut.

Future

When I see there's demand for further improvements I'll look what I can do. If you have better or additional ideas/solutions write an e-mail to Peter.

I'm also looking for a Mac and Linux solution which could do (some) of shortcuts commands. Last not least: many thanks go to Andreas Viebke, the author of shortcut, who also helped me with some questions :-)

Last modified: 2002-11-12