blob: 5ce3dc8c46fcce59b4a76c1a7e3ba5a0dcf9da99 [file] [log] [blame]
Bram Moolenaarafde13b2019-04-28 19:46:49 +02001*gui_w32.txt* For Vim version 8.1. Last change: 2019 Apr 28
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Vim's Win32 Graphical User Interface *gui-w32* *win32-gui*
8
91. Starting the GUI |gui-w32-start|
102. Vim as default editor |vim-default-editor|
113. Using the clipboard |gui-clipboard|
124. Shell Commands |gui-shell-win32|
135. Special colors |win32-colors|
146. Windows dialogs & browsers |gui-w32-dialogs|
157. Command line arguments |gui-w32-cmdargs|
168. Various |gui-w32-various|
17
18Other relevant documentation:
19|gui.txt| For generic items of the GUI.
Bram Moolenaarfa13eef2013-02-06 17:34:04 +010020|os_win32.txt| For Win32 specific items.
Bram Moolenaar071d4272004-06-13 20:20:40 +000021
22{Vi does not have a Windows GUI}
23
24==============================================================================
251. Starting the GUI *gui-w32-start*
26
27The Win32 GUI version of Vim will always start the GUI, no matter how you
28start it or what it's called.
29
30The GUI will always run in the Windows subsystem. Mostly shells automatically
31return with a command prompt after starting gvim. If not, you should use the
32"start" command: >
33 start gvim [options] file ..
Bram Moolenaarafde13b2019-04-28 19:46:49 +020034< *E988*
35The console version with the |-g| option may also start the GUI by executing
36gvim.exe: >
37 vim -g [options] file ..
38To make this work, gvim.exe must exist in the same directory as the vim.exe,
39and this feature must be enabled at compile time.
40
41One may also use `:gui` from the console version. However, this is an
42experimental feature and this feature must be enabled at compile time.
43It uses a session file to recreate the current state of the console Vim in the
44GUI Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +000045
46Note: All fonts (bold, italic) must be of the same size!!! If you don't do
47this, text will disappear or mess up the display. Vim does not check the font
48sizes. It's the size in screen pixels that must be the same. Note that some
49fonts that have the same point size don't have the same pixel size!
50Additionally, the positioning of the fonts must be the same (ascent and
51descent).
52
53The Win32 GUI has an extra menu item: "Edit/Select Font". It brings up the
54standard Windows font selector.
55
56Setting the menu height doesn't work for the Win32 GUI.
57
58 *gui-win32-maximized*
59If you want Vim to start with a maximized window, add this command to your
60vimrc or gvimrc file: >
61 au GUIEnter * simalt ~x
62<
Bram Moolenaar78e17622007-08-30 10:26:19 +000063
64Using Vim as a plugin *gui-w32-windowid*
65
66When gvim starts up normally, it creates its own top level window. If you
67pass Vim the command-line option |--windowid| with a decimal or hexadecimal
68value, Vim will create a window that is a child of the window with the given
69ID. This enables Vim to act as a plugin in another application. This really
70is a programmer's interface, and is of no use without a supporting application
71to spawn Vim correctly.
72
Bram Moolenaar071d4272004-06-13 20:20:40 +000073==============================================================================
742. Vim as default editor *vim-default-editor*
75
76To set Vim as the default editor for a file type:
771. Start a Windows Explorer
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000782. Choose View/Options -> File Types
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793. Select the path to gvim for every file type that you want to use it for.
80 (you can also use three spaces in the file type field, for files without an
81 extension).
82 In the "open" action, use: >
83 gvim "%1"
84< The quotes are required for using file names with embedded spaces.
85 You can also use this: >
86 gvim "%L"
87< This should avoid short (8.3 character) file names in some situations. But
88 I'm not sure if this works everywhere.
89
90When you open a file in Vim by double clicking it, Vim changes to that
91file's directory.
92
93If you want Vim to start full-screen, use this for the Open action: >
94 gvim -c "simalt ~x" "%1"
95
96Another method, which also works when you put Vim in another directory (e.g.,
97when you have got a new version):
981. select a file you want to use Vim with
992. <Shift-F10>
1003. select "Open With..." menu entry
1014. click "Other..."
1025. browse to the (new) location of Vim and click "Open"
1036. make "Always Use this program..." checked
1047. <OK>
105
106 *send-to-menu* *sendto*
107You can also install Vim in the "Send To" menu:
1081. Start a Windows Explorer
1092. Navigate to your sendto directory:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110 Windows NT: %windir%\profiles\%user%\sendto (e.g.
Bram Moolenaarcea912a2016-10-12 14:20:24 +0200111 "c:\winnt\profiles\mattha\sendto")
112 Windows XP: C:\Documents and Settings\%user%\SendTo
113 Windows Vista: C:\Users\%user%\AppData\Roaming\Microsoft\Windows\SendTo .
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143. Right-click in the file pane and select New->Shortcut
1154. Follow the shortcut wizard, using the full path to VIM/GVIM.
116
117When you 'send a file to Vim', Vim changes to that file's directory. Note,
118however, that any long directory names will appear in their short (MS-DOS)
119form. This is a limitation of the Windows "Send To" mechanism.
120
121 *notepad*
122You could replace notepad.exe with gvim.exe, but that has a few side effects.
123Some programs rely on notepad arguments, which are not recognized by Vim. For
124example "notepad -p" is used by some applications to print a file. It's
125better to leave notepad where it is and use another way to start Vim.
126
127 *win32-popup-menu*
128A more drastic approach is to install an "Edit with Vim" entry in the popup
129menu for the right mouse button. With this you can edit any file with Vim.
130
131This can co-exist with the file associations mentioned above. The difference
132is that the file associations will make starting Vim the default action. With
133the "Edit with Vim" menu entry you can keep the existing file association for
134double clicking on the file, and edit the file with Vim when you want. For
135example, you can associate "*.mak" with your make program. You can execute
136the makefile by double clicking it and use the "Edit with Vim" entry to edit
137the makefile.
138
139You can select any files and right-click to see a menu option called "Edit
Bram Moolenaarc236c162008-07-13 17:41:49 +0000140with gvim". Choosing this menu option will invoke gvim with the file you have
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141selected. If you select multiple files, you will find two gvim-related menu
142options:
143"Edit with multiple gvims" -- one gvim for each file in the selection
144"Edit with single gvim" -- one gvim for all the files in the selection
145And if there already is a gvim running:
146"Edit with existing gvim" -- edit the file with the running gvim
147
Bram Moolenaar5302d9e2011-09-14 17:55:08 +0200148The "edit with existing Vim" entries can be disabled by adding an entry in the
149registry under HKLM\Software\Vim\Gvim, named DisableEditWithExisting, and with
150any value.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151 *install-registry*
152You can add the "Edit with Vim" menu entry in an easy way by using the
153"install.exe" program. It will add several registry entries for you.
154
155You can also do this by hand. This is complicated! Use the install.exe if
156you can.
157
1581. Start the registry editor with "regedit".
1592. Add these keys:
160 key value name value ~
161 HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}
162 {default} Vim Shell Extension
163 HKEY_CLASSES_ROOT\CLSID\{51EEE242-AD87-11d3-9C1E-0090278BBD99}\InProcServer32
164 {default} {path}\gvimext.dll
165 ThreadingModel Apartment
166 HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\gvim
167 {default} {51EEE242-AD87-11d3-9C1E-0090278BBD99}
168 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved
169 {51EEE242-AD87-11d3-9C1E-0090278BBD99}
170 Vim Shell Extension
171 HKEY_LOCAL_MACHINE\Software\Vim\Gvim
172 path {path}\gvim.exe
173 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\vim 5.6
174 DisplayName Vim 5.6: Edit with Vim popup menu entry
175 UninstallString {path}\uninstal.exe
176
177 Replace {path} with the path that leads to the executable.
178 Don't type {default}, this is the value for the key itself.
179
180To remove "Edit with Vim" from the popup menu, just remove the registry
181entries mentioned above. The "uninstal.exe" program can do this for you. You
182can also use the entry in the Windows standard "Add/Remove Programs" list.
183
184If you notice that this entry overrules other file type associations, set
185those associations again by hand (using Windows Explorer, see above). This
186only seems to happen on some Windows NT versions (Windows bug?). Procedure:
1871. Find the name of the file type. This can be done by starting the registry
188 editor, and searching for the extension in \\HKEY_CLASSES_ROOT
1892. In a Windows Explorer, use View/Options/File Types. Search for the file
190 type in the list and click "Edit". In the actions list, you can select on
191 to be used as the default (normally the "open" action) and click on the
192 "Set Default" button.
193
194
195Vim in the "Open With..." context menu *win32-open-with-menu*
196
197If you use the Vim install program you have the choice to add Vim to the "Open
198With..." menu. This means you can use Vim to edit many files. Not every file
199(for unclear reasons...), thus the "Edit with Vim" menu entry is still useful.
200
201One reason to add this is to be able to edit HTML files directly from Internet
202Explorer. To enable this use the "Tools" menu, "Internet Options..." entry.
203In the dialog select the "Programs" tab and select Vim in the "HTML editor"
204choice. If it's not there than installing didn't work properly.
205
206Doing this manually can be done with this script:
207
208----------------------------------------------------------
209REGEDIT4
210
211[HKEY_CLASSES_ROOT\Applications\gvim.exe]
212
213[HKEY_CLASSES_ROOT\Applications\gvim.exe\shell]
214
215[HKEY_CLASSES_ROOT\Applications\gvim.exe\shell\edit]
216
217[HKEY_CLASSES_ROOT\Applications\gvim.exe\shell\edit\command]
218@="c:\\vim\\vim62\\gvim.exe \"%1\""
219
220[HKEY_CLASSES_ROOT\.htm\OpenWithList\gvim.exe]
221
222[HKEY_CLASSES_ROOT\*\OpenWithList\gvim.exe]
223
224----------------------------------------------------------
225
226Change the "c:\\vim\\vim62" bit to where gvim.exe is actually located.
227
228To uninstall this run the Vim uninstall program or manually delete the
229registry entries with "regedit".
230
231==============================================================================
2323. Using the clipboard *gui-clipboard*
233
234Windows has a clipboard, where you can copy text to, and paste text from. Vim
235supports this in several ways. For other systems see |gui-selections|.
236
237The "* register reflects the contents of the clipboard. |quotestar|
238
239When the "unnamed" string is included in the 'clipboard' option, the unnamed
240register is the same. Thus you can yank to and paste from the clipboard
241without prepending "* to commands.
242
243The 'a' flag in 'guioptions' is not included by default. This means that text
244is only put on the clipboard when an operation is performed on it. Just
245Visually selecting text doesn't put it on the clipboard. When the 'a' flag is
246included, the text is copied to the clipboard even when it is not operated
247upon.
248
249 *mswin.vim*
250To use the standard MS-Windows way of CTRL-X, CTRL-C and CTRL-V, use the
251$VIMRUNTIME/mswin.vim script. You could add this line to your _vimrc file: >
252 source $VIMRUNTIME/mswin.vim
253
254Since CTRL-C is used to copy the text to the clipboard, it can't be used to
255cancel an operation. Use CTRL-Break for that.
256
Bram Moolenaar9964e462007-05-05 17:54:07 +0000257CTRL-Z is used for undo. This means you can't suspend Vim with this key, use
258|:suspend| instead (if it's supported at all).
Bram Moolenaar6f7926c2005-01-07 21:45:22 +0000259
Bram Moolenaardf177f62005-02-22 08:39:57 +0000260 *CTRL-V-alternative* *CTRL-Q*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261Since CTRL-V is used to paste, you can't use it to start a blockwise Visual
262selection. You can use CTRL-Q instead. You can also use CTRL-Q in Insert
263mode and Command-line mode to get the old meaning of CTRL-V. But CTRL-Q
264doesn't work for terminals when it's used for control flow.
265
266NOTE: The clipboard support still has a number of bugs. See |todo|.
267
268==============================================================================
2694. Shell Commands *gui-shell-win32*
270
271Vim uses another window for external commands, to make it possible to run any
272command. The external command gets its own environment for running, just like
273it was started from a DOS prompt.
274
275 *win32-vimrun*
276Executing an external command is done indirectly by the "vimrun" command. The
277"vimrun.exe" must be in the path for this to work. Or it must be in the same
278directory as the Vim executable. If "vimrun" cannot be found, the command is
279executed directly, but then the DOS window closes immediately after the
280external command has finished.
281WARNING: If you close this window with the "X" button, and confirm the
282question if you really want to kill the application, Vim may be killed too!
283(This does not apply to commands run asynchronously with ":!start".)
284
Bram Moolenaarcea912a2016-10-12 14:20:24 +0200285The window in which the commands are executed will be the default you have set
286up for "Console" in Control Panel.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287
288 *win32-!start*
289Normally, Vim waits for a command to complete before continuing (this makes
290sense for most shell commands which produce output for Vim to use). If you
291want Vim to start a program and return immediately, you can use the following
Bram Moolenaarcea912a2016-10-12 14:20:24 +0200292syntax: >
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +0100293 :!start [/min] {command}
294The optional "/min" causes the window to be minimized.
295
Bram Moolenaar071d4272004-06-13 20:20:40 +0000296==============================================================================
2975. Special colors *win32-colors*
298
299On Win32, the normal DOS colors can be used. See |dos-colors|.
300
301Additionally the system configured colors can also be used. These are known
302by the names Sys_XXX, where XXX is the appropriate system color name, from the
303following list (see the Win32 documentation for full descriptions). Case is
Bram Moolenaarcea912a2016-10-12 14:20:24 +0200304ignored.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305
306Sys_3DDKShadow Sys_3DFace Sys_BTNFace
307Sys_3DHilight Sys_3DHighlight Sys_BTNHilight
308Sys_BTNHighlight Sys_3DLight Sys_3DShadow
309Sys_BTNShadow Sys_ActiveBorder Sys_ActiveCaption
310Sys_AppWorkspace Sys_Background Sys_Desktop
311Sys_BTNText Sys_CaptionText Sys_GrayText
312Sys_Highlight Sys_HighlightText Sys_InactiveBorder
313Sys_InactiveCaption Sys_InactiveCaptionText Sys_InfoBK
314Sys_InfoText Sys_Menu Sys_MenuText
315Sys_ScrollBar Sys_Window Sys_WindowFrame
316Sys_WindowText
317
318Probably the most useful values are
319 Sys_Window Normal window background
320 Sys_WindowText Normal window text
321 Sys_Highlight Highlighted background
322 Sys_HighlightText Highlighted text
323
324These extra colors are also available:
325Gray, Grey, LightYellow, SeaGreen, Orange, Purple, SlateBlue, Violet,
326
327 *rgb.txt*
328Additionally, colors defined by a "rgb.txt" file can be used. This file is
329well known from X11. A few lines from it: >
330
331 255 218 185 peach puff
332 205 133 63 peru
333 255 181 197 pink
334
335This shows the layout of the file: First the R, G and B value as a decimal
336number, followed by the name of the color. The four fields are separated by
337spaces.
338
339You can get an rgb.txt file from any X11 distribution. It is located in a
340directory like "/usr/X11R6/lib/X11/". For Vim it must be located in the
341$VIMRUNTIME directory. Thus the file can be found with "$VIMRUNTIME/rgb.txt".
342
343==============================================================================
344 *gui-w32-dialogs* *dialog*
3456. Windows dialogs & browsers
346
347The Win32 GUI can use familiar Windows components for some operations, as well
348as the traditional interface shared with the console version.
349
350
3516.1 Dialogs
352
353The dialogs displayed by the "confirm" family (i.e. the 'confirm' option,
354|:confirm| command and |confirm()| function) are GUI-based rather than the
355console-based ones used by other versions. The 'c' flag in 'guioptions'
356changes this.
357
358
3596.2 File Browsers
360
361When prepending ":browse" before file editing commands, a file requester is
362used to allow you to select an existing file. See |:browse|.
363
364
3656.3 Tearoff Menus
366
367The Win32 GUI emulates Motif's tear-off menus. At the top of each menu you
368will see a small graphic "rip here" sign. Selecting it will cause a floating
369window to be created with the same menu entries on it. The floating menu can
370then be accessed just as if it was the original (including sub-menus), but
371without having to go to the menu bar each time.
372This is most useful if you find yourself using a command buried in a sub-menu
373over and over again.
374The tearoff menus can be positioned where you like, and always stay just above
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000375the Main Vim window. You can get rid of them by closing them as usual; they
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376also of course close when you exit Vim.
377
378 *:tearoff* *:te*
379:te[aroff] {name} Tear-off the menu {name}. The menu named must have at
380 least one subentry, but need not appear on the
381 menu-bar (see |win32-hidden-menus|).
382
383Example: >
384 :tearoff File
385will make the "File" menu (if there is one) appear as a tearoff menu. >
386
387 :amenu ]Toolbar.Make :make<CR>
388 :tearoff ]Toolbar
389This creates a floating menu that doesn't exist on the main menu-bar.
390
391Note that a menu that starts with ']' will not be displayed.
392
393==============================================================================
3947. Command line arguments *gui-w32-cmdargs*
395
Bram Moolenaar01164a62017-11-02 22:58:42 +0100396Command line arguments behave the same way as with the console application,
397see |win32-cmdargs|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398
399==============================================================================
4008. Various *gui-w32-various*
401
402 *gui-w32-printing*
403The "File/Print" menu prints the text with syntax highlighting, see
404|:hardcopy|. If you just want to print the raw text and have a default
405printer installed this should also work: >
406 :w >>prn
407
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000408Vim supports a number of standard MS Windows features. Some of these are
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409detailed elsewhere: see |'mouse'|, |win32-hidden-menus|.
410
411 *drag-n-drop-win32*
412You can drag and drop one or more files into the Vim window, where they will
413be opened as normal. See |drag-n-drop|.
414
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100415 *:simalt* *:sim*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000416:sim[alt] {key} simulate pressing {key} while holding Alt pressed.
417 {not in Vi} {only for Win32 versions}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100418 Note: ":si" means ":s" with the "i" flag.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000419
420Normally, Vim takes control of all Alt-<Key> combinations, to increase the
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000421number of possible mappings. This clashes with the standard use of Alt as the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000422key for accessing menus.
423The quick way of getting standard behavior is to set the 'winaltkeys' option
424to "yes". This however prevents you from mapping Alt keys at all.
425Another way is to set 'winaltkeys' to "menu". Menu shortcut keys are then
426handled by windows, other ALT keys can be mapped. This doesn't allow a
427dependency on the current state though.
428To get round this, the :simalt command allows Vim (when 'winaltkeys' is not
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000429"yes") to fake a Windows-style Alt keypress. You can use this to map Alt key
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430combinations (or anything else for that matter) to produce standard Windows
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000431actions. Here are some examples: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000432
433 :map <M-f> :simalt f<CR>
434This makes Alt-F pop down the 'File' menu (with the stock Menu.vim) by
435simulating the keystrokes Alt, F. >
436 :map <M-Space> :simalt ~<CR>
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000437This maps Alt-Space to pop down the system menu for the Vim window. Note that
Bram Moolenaar071d4272004-06-13 20:20:40 +0000438~ is used by simalt to represent the <Space> character. >
439 :map <C-n> :simalt ~n<CR>
Bram Moolenaar402d2fe2005-04-15 21:00:38 +0000440Maps Control-N to produce the keys Alt-Space followed by N. This minimizes the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441Vim window via the system menu.
442
Bram Moolenaar9964e462007-05-05 17:54:07 +0000443Note that the key changes depending on the language you are using.
444
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445 *intellimouse-wheel-problems*
446When using the Intellimouse mouse wheel causes Vim to stop accepting input, go
447to:
448 ControlPanel - Mouse - Wheel - UniversalScrolling - Exceptions
449
450And add gvim to the list of applications. This problem only appears to happen
451with the Intellimouse driver 2.2 and when "Universal Scrolling" is turned on.
452
Bram Moolenaar9b451252012-08-15 17:43:31 +0200453
454XPM support *w32-xpm-support*
455
Bram Moolenaarb477af22018-07-15 20:20:18 +0200456GVim can be build on MS-Windows with support for XPM files. |+xpm_w32|
Bram Moolenaar9b451252012-08-15 17:43:31 +0200457See the Make_mvc.mak file for instructions, search for XPM.
458
459To try out if XPM support works do this: >
460 :help
461 :exe 'sign define vimxpm icon=' . $VIMRUNTIME . '\\vim16x16.xpm'
462 :exe 'sign place 1 line=1 name=vimxpm file=' . expand('%:p')
463<
464
Bram Moolenaar91f84f62018-07-29 15:07:52 +0200465 vim:tw=78:sw=4:ts=8:noet:ft=help:norl: