gui_w32.txt 19 KB

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