os_win32.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. *os_win32.txt* For Vim version 9.0. Last change: 2022 Sep 18
  2. VIM REFERENCE MANUAL by George Reilly
  3. *win32* *Win32* *MS-Windows*
  4. This file documents the idiosyncrasies of the Win32 version of Vim.
  5. The Win32 version of Vim works on Windows 7, 8, 10 and 11. There are both
  6. console and GUI versions.
  7. If you have Windows XP or Vista then Vim 9.0 up to patch level 495 can be
  8. used.
  9. The 32 bit version also runs on 64 bit MS-Windows systems.
  10. 1. Known problems |win32-problems|
  11. 2. Startup |win32-startup|
  12. 3. Restore screen contents |win32-restore|
  13. 4. Using the mouse |win32-mouse|
  14. 5. Running under Windows 95 |win32-win95|
  15. 6. Running under Windows 3.1 |win32-win3.1|
  16. 7. Installation package |win32-installer|
  17. 8. Win32 mini FAQ |win32-faq|
  18. Additionally, there are a number of common Win32 and DOS items:
  19. File locations |dos-locations|
  20. Using backslashes |dos-backslash|
  21. Standard mappings |dos-standard-mappings|
  22. Screen output and colors |dos-colors|
  23. File formats |dos-file-formats|
  24. :cd command |dos-:cd|
  25. Interrupting |dos-CTRL-Break|
  26. Temp files |dos-temp-files|
  27. Shell option default |dos-shell|
  28. PowerShell defaults |dos-powershell|
  29. Win32 GUI |gui-w32|
  30. Credits:
  31. The Win32 version was written by George V. Reilly <george@reilly.org>.
  32. The original Windows NT port was done by Roger Knobbe <RogerK@wonderware.com>.
  33. The GUI version was made by George V. Reilly and Robert Webb.
  34. For compiling see "src/INSTALLpc.txt". *win32-compiling*
  35. *WSL*
  36. When using Vim on WSL (Windows Subsystem for Linux) the remarks here do not
  37. apply, `has('win32')` will return false then. In case you need to know
  38. whether Vim is running on WSL you can use `exists('$WSLENV')`.
  39. ==============================================================================
  40. 1. Known problems *win32-problems*
  41. When doing file name completion, Vim also finds matches for the short file
  42. name. But Vim will still find and use the corresponding long file name. For
  43. example, if you have the long file name "this_is_a_test" with the short file
  44. name "this_i~1", the command ":e *1" will start editing "this_is_a_test".
  45. ==============================================================================
  46. 2. Startup *win32-startup*
  47. Current directory *win32-curdir*
  48. If Vim is started with a single file name argument, and it has a full path
  49. (starts with "x:\"), Vim assumes it was started from the file explorer and
  50. will set the current directory to where that file is. To avoid this when
  51. typing a command to start Vim, use a forward slash instead of a backslash.
  52. Example: >
  53. vim c:\text\files\foo.txt
  54. Will change to the "C:\text\files" directory. >
  55. vim c:/text\files\foo.txt
  56. Will use the current directory.
  57. Term option *win32-term*
  58. The only kind of terminal type that the Win32 version of Vim understands is
  59. "win32", which is built-in. If you set 'term' to anything else, you will
  60. probably get very strange behavior from Vim. Therefore Vim does not obtain
  61. the default value of 'term' from the environment variable "TERM".
  62. $PATH *win32-PATH*
  63. The directory of the Vim executable is appended to $PATH. This is mostly to
  64. make "!xxd" work, as it is in the Tools menu. And it also means that when
  65. executable() returns 1 the executable can actually be executed.
  66. Command line arguments *win32-cmdargs*
  67. Analysis of a command line into parameters is not standardised in MS-Windows.
  68. Vim and gvim used to use different logic to parse it (before 7.4.432), and the
  69. logic was also depended on what it was compiled with. Now Vim and gvim both
  70. use the CommandLineToArgvW() Win32 API, so they behave in the same way.
  71. The basic rules are: *win32-backslashes*
  72. a) A parameter is a sequence of graphic characters.
  73. b) Parameters are separated by white space.
  74. c) A parameter can be enclosed in double quotes to include white space.
  75. d) A sequence of zero or more backslashes (\) and a double quote (")
  76. is special. The effective number of backslashes is halved, rounded
  77. down. An even number of backslashes reverses the acceptability of
  78. spaces and tabs, an odd number of backslashes produces a literal
  79. double quote.
  80. So:
  81. " is a special double quote
  82. \" is a literal double quote
  83. \\" is a literal backslash and a special double quote
  84. \\\" is a literal backslash and a literal double quote
  85. \\\\" is 2 literal backslashes and a special double quote
  86. \\\\\" is 2 literal backslashes and a literal double quote
  87. etc.
  88. Example: >
  89. vim "C:\My Music\freude" +"set ignorecase" +/"\"foo\\" +\"bar\\\"
  90. opens "C:\My Music\freude" and executes the line mode commands: >
  91. set ignorecase; /"foo\ and /bar\"
  92. These rules are also described in the reference of the CommandLineToArgvW API:
  93. https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391.aspx
  94. *win32-quotes*
  95. There are additional rules for quotes (which are not well documented).
  96. As described above, quotes inside a file name (or any other command line
  97. argument) can be escaped with a backslash. E.g. >
  98. vim -c "echo 'foo\"bar'"
  99. Alternatively use three quotes to get one: >
  100. vim -c "echo 'foo"""bar'"
  101. The quotation rules are:
  102. 1. A `"` starts quotation.
  103. 2. Another `"` or `""` ends quotation. If the quotation ends with `""`, a `"`
  104. is produced at the end of the quoted string.
  105. Examples, with [] around an argument:
  106. "foo" -> [foo]
  107. "foo"" -> [foo"]
  108. "foo"bar -> [foobar]
  109. "foo" bar -> [foo], [bar]
  110. "foo""bar -> [foo"bar]
  111. "foo"" bar -> [foo"], [bar]
  112. "foo"""bar" -> [foo"bar]
  113. ==============================================================================
  114. 3. Restore screen contents *win32-restore*
  115. When 'restorescreen' is set (which is the default), Vim will restore the
  116. original contents of the console when exiting or when executing external
  117. commands. If you don't want this, use ":set nors". |'restorescreen'|
  118. ==============================================================================
  119. 4. Using the mouse *win32-mouse*
  120. The Win32 version of Vim supports using the mouse. If you have a two-button
  121. mouse, the middle button can be emulated by pressing both left and right
  122. buttons simultaneously - but note that in the Win32 GUI, if you have the right
  123. mouse button pop-up menu enabled (see 'mouse'), you should err on the side of
  124. pressing the left button first. |mouse-using|
  125. When the mouse doesn't work, try disabling the "Quick Edit Mode" feature of
  126. the console.
  127. ==============================================================================
  128. 5. Running under Windows 95 *win32-win95*
  129. *windows95* *windows98* *windowsme*
  130. Windows 95/98/ME support was removed in patch 8.0.0029 If you want to use it
  131. you will need to get a version older than that.
  132. ==============================================================================
  133. 6. Running under Windows 3.1 *win32-win3.1*
  134. *win32s* *windows-3.1* *gui-w32s* *win16*
  135. There was a special version of gvim that runs under Windows 3.1 and 3.11.
  136. Support was removed in patch 7.4.1364.
  137. ==============================================================================
  138. 7. Installation package *win32-installer*
  139. A simple installer for windows is available at http://www.vim.org/download.php
  140. (stable version) and nightly builds are also available at
  141. https://github.com/vim/vim-win32-installer/releases/
  142. The nightly builds include 32bit and 64bit builds, have most features enabled
  143. and usually also contain an extra cryptographic signed installer, so Windows
  144. will not complain.
  145. To use the installer, simply run the exe file. The following switches are
  146. also supported: >
  147. gvim_<version>.exe /S -> silent install without any dialogues
  148. gvim_<version>.exe /D=C:\vim -> Install into directory c:\vim
  149. -> /D must be the last argument
  150. gvim_<version>.exe /S /D=c:\vim -> silent install into c:\vim
  151. <
  152. The default installation directory can alternatively be given by setting the
  153. $VIM environment variable.
  154. ==============================================================================
  155. 8. Win32 mini FAQ *win32-faq*
  156. Q. How do I change the font?
  157. A. In the GUI version, you can use the 'guifont' option. Example: >
  158. :set guifont=Lucida_Console:h15:cDEFAULT
  159. < In the console version, you need to set the font of the console itself.
  160. You cannot do this from within Vim.
  161. Q. How do I type dead keys on Windows NT?
  162. A. Dead keys work on NT 3.51. Just type them as you would in any other
  163. application.
  164. On NT 4.0, you need to make sure that the default locale (set in the
  165. Keyboard part of the Control Panel) is the same as the currently active
  166. locale. Otherwise the NT code will get confused and crash! This is a NT
  167. 4.0 problem, not really a Vim problem.
  168. Q. I'm using Vim to edit a symbolically linked file on a Unix NFS file server.
  169. When I write the file, Vim does not "write through" the symlink. Instead,
  170. it deletes the symbolic link and creates a new file in its place. Why?
  171. A. On Unix, Vim is prepared for links (symbolic or hard). A backup copy of
  172. the original file is made and then the original file is overwritten. This
  173. assures that all properties of the file remain the same. On non-Unix
  174. systems, the original file is renamed and a new file is written. Only the
  175. protection bits are set like the original file. However, this doesn't work
  176. properly when working on an NFS-mounted file system where links and other
  177. things exist. The only way to fix this in the current version is not
  178. making a backup file, by ":set nobackup nowritebackup" |'writebackup'|
  179. Q. I'm using Vim to edit a file on a Unix file server through Samba. When I
  180. write the file, the owner of the file is changed. Why?
  181. A. When writing a file Vim renames the original file, this is a backup (in
  182. case writing the file fails halfway). Then the file is written as a new
  183. file. Samba then gives it the default owner for the file system, which may
  184. differ from the original owner.
  185. To avoid this set the 'backupcopy' option to "yes". Vim will then make a
  186. copy of the file for the backup, and overwrite the original file. The
  187. owner isn't changed then.
  188. Q. How do I get to see the output of ":make" while it's running?
  189. A. Basically what you need is to put a tee program that will copy its input
  190. (the output from make) to both stdout and to the errorfile. You can find a
  191. copy of tee (and a number of other GNU tools) at
  192. http://gnuwin32.sourceforge.net or http://unxutils.sourceforge.net
  193. Alternatively, try the more recent Cygnus version of the GNU tools at
  194. http://www.cygwin.com Other Unix-style tools for Win32 are listed at
  195. http://directory.google.com/Top/Computers/Software/Operating_Systems/Unix/Win32/
  196. When you do get a copy of tee, you'll need to add >
  197. :set shellpipe=\|\ tee
  198. < to your _vimrc.
  199. Q. I'm storing files on a remote machine that works with VisionFS, and files
  200. disappear!
  201. A. VisionFS can't handle certain dot (.) three letter extension file names.
  202. SCO declares this behavior required for backwards compatibility with 16bit
  203. DOS/Windows environments. The two commands below demonstrate the behavior:
  204. >
  205. echo Hello > file.bat~
  206. dir > file.bat
  207. <
  208. The result is that the "dir" command updates the "file.bat~" file, instead
  209. of creating a new "file.bat" file. This same behavior is exhibited in Vim
  210. when editing an existing file named "foo.bat" because the default behavior
  211. of Vim is to create a temporary file with a '~' character appended to the
  212. name. When the file is written, it winds up being deleted.
  213. Solution: Add this command to your _vimrc file: >
  214. :set backupext=.temporary
  215. Q. How do I change the blink rate of the cursor?
  216. A. You can't! This is a limitation of the NT console. NT 5.0 is reported to
  217. be able to set the blink rate for all console windows at the same time.
  218. *:!start*
  219. Q. How can I asynchronously run an external command or program, or open a
  220. document or URL with its default program?
  221. A. When using :! to run an external command, you can run it with "start". For
  222. example, to run notepad: >
  223. :!start notepad
  224. < To open "image.jpg" with the default image viewer: >
  225. :!start image.jpg
  226. < To open the folder of the current file in Windows Explorer: >
  227. :!start %:h
  228. < To open the Vim home page with the default browser: >
  229. :!start http://www.vim.org/
  230. <
  231. Using "start" stops Vim switching to another screen, opening a new console,
  232. or waiting for the program to complete; it indicates that you are running a
  233. program that does not affect the files you are editing. Programs begun
  234. with :!start do not get passed Vim's open file handles, which means they do
  235. not have to be closed before Vim.
  236. To avoid this special treatment, use ":! start".
  237. There are two optional arguments (see the next Q):
  238. /min the window will be minimized
  239. /b no console window will be opened
  240. You can use only one of these flags at a time. A second one will be
  241. treated as the start of the command.
  242. *windows-asynchronously*
  243. Q. How do I avoid getting a window for programs that I run asynchronously?
  244. A. You have two possible solutions depending on what you want:
  245. 1) You may use the /min flag in order to run program in a minimized state
  246. with no other changes. It will work equally for console and GUI
  247. applications.
  248. 2) You can use the /b flag to run console applications without creating a
  249. console window for them (GUI applications are not affected). But you
  250. should use this flag only if the application you run doesn't require any
  251. input. Otherwise it will get an EOF error because its input stream
  252. (stdin) would be redirected to \\.\NUL (stdout and stderr too).
  253. Example for a console application, run Exuberant ctags: >
  254. :!start /min ctags -R .
  255. < When it has finished you should see file named "tags" in your current
  256. directory. You should notice the window title blinking on your taskbar.
  257. This is more noticeable for commands that take longer.
  258. Now delete the "tags" file and run this command: >
  259. :!start /b ctags -R .
  260. < You should have the same "tags" file, but this time there will be no
  261. blinking on the taskbar.
  262. Example for a GUI application: >
  263. :!start /min notepad
  264. :!start /b notepad
  265. < The first command runs notepad minimized and the second one runs it
  266. normally.
  267. *windows-icon*
  268. Q. I don't like the Vim icon, can I change it?
  269. A. Yes, place your favorite icon in bitmaps/vim.ico in a directory of
  270. 'runtimepath'. For example ~/vimfiles/bitmaps/vim.ico.
  271. vim:tw=78:ts=8:noet:ft=help:norl: