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.
It's time for a quick oversight over the possibilities shortcut offers:
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".
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.
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.
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.
In Vim the changed text is saved into a file (into the temp directory to the file shortclip2.txt), before it's copied to the clipboard. So you're having a save copy if something might go wrong in the process to copy the text to the clipboard and to paste it back to the original application. Problems might occur, when you're calling the shorcut-macro and you're in normal mode as opposed to insert mode. With carefully chosen shortcuts this won't be a problem in normal mode too. Also it might be an idea to make a mapping in normal mode of Vim which takes care that the shortcut-macro does not interferes with a Vim normal command.
In the original application there's also a copy made before the text is pasted to Vim. This file in the systems temp directory is called shortclip.txt. Both backups are not really needed and you can omit the calls in the macro if you've found the solution to work for you and you don't want to have an extra backup copy :-)
#vv
and
#vb
fast to type for vi and vi-back. Those two macros take care of the clipboards content. The clipboard will be used to copy/paste the text, but is restored automatic so that you don't have to worry about losing the clipboards content. This solution turned out not to work always, due a problem inside shortcut. In the new shortcut version 3.3.6.0 the problems have been solved, but to be on the save side I added the above mentioned backup copies. You may decide if you want to use the vim/vz or the vi/vb macros. The only difference is the recovery of the clipboard.
BTW, to cut/paste the text in Vim I've used the Vim normal mode commands ("+d or "+P), so you won't see any conflicts here :-)
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.
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.
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.
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