blob: f2ce9eb74af22b8cd21df797bab120d48b8fd262 [file] [log] [blame]
Bram Moolenaar5c5474b2005-04-19 21:40:26 +00001*starting.txt* For Vim version 7.0aa. Last change: 2005 Apr 18
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Starting Vim *starting*
8
91. Vim arguments |vim-arguments|
102. Vim on the Amiga |starting-amiga|
113. Running eVim |evim-keys|
124. Initialization |initialization|
135. $VIM and $VIMRUNTIME |$VIM|
146. Suspending |suspend|
157. Saving settings |save-settings|
168. Views and Sessions |views-sessions|
179. The viminfo file |viminfo-file|
18
19==============================================================================
201. Vim arguments *vim-arguments*
21
22Most often, Vim is started to edit a single file with the command
23
24 vim filename *-vim*
25
26More generally, Vim is started with:
27
28 vim [option | filename] ..
29
30Option arguments and file name arguments can be mixed, and any number of them
31can be given. However, watch out for options that take an argument.
32
33For compatibility with various Vi versions, see |cmdline-arguments|.
34
35Exactly one out of the following five items may be used to choose how to
36start editing:
37
38 *-file* *---*
39filename One or more file names. The first one will be the current
40 file and read into the buffer. The cursor will be positioned
41 on the first line of the buffer.
42 To avoid a file name starting with a '-' being interpreted as
43 an option, precede the arglist with "--", e.g.: >
44 vim -- -filename
45< All arguments after the "--" will be interpreted as file names,
46 no other options or "+command" argument can follow.
47
48 *--*
49- This argument can mean two things, depending on whether Ex
50 mode is to be used.
51
52 Starting in Normal mode: >
53 vim -
54 ex -v -
55< Start editing a new buffer, which is filled with text
56 that is read from stdin. The commands that would normally be
57 read from stdin will now be read from stderr. Example: >
58 find . -name "*.c" -print | vim -
59< The buffer will be marked modified, because it contains text
60 that needs to be saved. Except when in readonly mode, then
61 the buffer is not marked modified. Example: >
62 ls | view -
63<
64 Starting in Ex mode: >
65 ex -
66 vim -e -
67 exim -
68 vim -E
69< Start editing in silent mode. See |-s-ex|.
70
71 *-t* *-tag*
72-t {tag} A tag. "tag" is looked up in the tags file, the associated
73 file becomes the current file, and the associated command is
74 executed. Mostly this is used for C programs, in which case
75 "tag" often is a function name. The effect is that the file
76 containing that function becomes the current file and the
77 cursor is positioned on the start of the function (see
78 |tags|).
79
80 *-q* *-qf*
81-q [errorfile] QuickFix mode. The file with the name [errorfile] is read
82 and the first error is displayed. See |quickfix|.
83 If [errorfile] is not given, the 'errorfile' option is used
84 for the file name. See 'errorfile' for the default value.
85 {not in Vi}
86
87(nothing) Without one of the four items above, Vim will start editing a
88 new buffer. It's empty and doesn't have a file name.
89
90
91The startup mode can be changed by using another name instead of "vim", which
92is equal to giving options:
93ex vim -e Start in Ex mode (see |Ex-mode|). *ex*
94exim vim -E Start in improved Ex mode (see |Ex-mode|). *exim*
95 (normally not installed)
96view vim -R Start in read-only mode (see |-R|). *view*
97gvim vim -g Start the GUI (see |gui|). *gvim*
98gex vim -eg Start the GUI in Ex mode. *gex*
99gview vim -Rg Start the GUI in read-only mode. *gview*
100rvim vim -Z Like "vim", but in restricted mode (see |-Z|) *rvim*
101rview vim -RZ Like "view", but in restricted mode. *rview*
102rgvim vim -gZ Like "gvim", but in restricted mode. *rgvim*
103rgview vim -RgZ Like "gview", but in restricted mode. *rgview*
104evim vim -y Easy Vim: set 'insertmode' (see |-y|) *evim*
105eview vim -yR Like "evim" in read-only mode *eview*
106vimdiff vim -d Start in diff mode |diff-mode|
107gvimdiff vim -gd Start in diff mode |diff-mode|
108
109Additional characters may follow, they are ignored. For example, you can have
110"gvim-5" to start the GUI. You must have an executable by that name then, of
111course.
112
113On Unix, you would normally have one executable called Vim, and links from the
114different startup-names to that executable. If your system does not support
115links and you do not want to have several copies of the executable, you could
116use an alias instead. For example: >
117 alias view vim -R
118 alias gvim vim -g
119<
120 *startup-options*
121The option arguments may be given in any order. Single-letter options can be
122combined after one dash. There can be no option arguments after the "--"
123argument.
124
125On VMS all option arguments are assumed to be lowercase, unless preceded with
126a slash. Thus "-R" means recovery and "-/R" readonly.
127
128--help *-h* *--help*
129-h Give usage (help) message and exit. {not in Vi}
130 See |info-message| about capturing the text.
131
132 *--version*
133--version Print version information and exit. Same output as for
134 |:version| command. {not in Vi}
135 See |info-message| about capturing the text.
136
137 *--noplugin*
138--noplugin Skip loading plugins. Resets the 'loadplugins' option.
139 {not in Vi}
140 Note that the |-u| argument may also disable loading plugins:
141 argument load vimrc files load plugins ~
142 (nothing) yes yes
143 -u NONE no no
144 -u NORC no yes
145 --noplugin yes no
146
147 *--literal*
148--literal Take file names literally, don't expand wildcards. Not needed
149 for Unix, because Vim always takes file names literally (the
150 shell expands wildcards).
151 Applies to all the names, also the ones that come before this
152 argument.
153
154 *-+*
155+[num] The cursor will be positioned on line "num" for the first
156 file being edited. If "num" is missing, the cursor will be
157 positioned on the last line.
158
159 *-+/*
160+/{pat} The cursor will be positioned on the first line containing
161 "pat" in the first file being edited (see |pattern| for the
162 available search patterns).
163
164+{command} *-+c* *-c*
165-c {command} {command} will be executed after the first file has been
166 read (and after autocommands and modelines for that file have
167 been processed). "command" is interpreted as an Ex command.
168 If the "command" contains spaces, it must be enclosed in
169 double quotes (this depends on the shell that is used).
170 Example: >
171 vim "+set si" main.c
172 vim "+find stdio.h"
173 vim -c "set ff=dos" -c wq mine.mak
174<
175 Note: You can use up to 10 "+" or "-c" arguments in a Vim
176 command. They are executed in the order given. A "-S"
177 argument counts as a "-c" argument as well.
178 {Vi only allows one command}
179
180--cmd {command} *--cmd*
181 {command} will be executed before processing any vimrc file.
182 Otherwise it acts like -c {command}. You can use up to 10 of
183 these commands, independently from "-c" commands.
184 {not in Vi}
185
186 *-S*
187-S {file} The {file} will be sourced after the first file has been read.
188 This is an easy way to do the equivalent of: >
189 -c "source {file}"
190< It can be mixed with "-c" arguments and repeated like "-c".
191 The limit of 10 "-c" arguments applies here as well.
192 {file} cannot start with a "-".
193 {not in Vi}
194
195-S Works like "-S Session.vim". Only when used as the last
196 argument or when another "-" option follows.
197
198 *-r*
199-r Recovery mode. Without a file name argument, a list of
200 existing swap files is given. With a file name, a swap file
201 is read to recover a crashed editing session. See
202 |crash-recovery|.
203
204 *-L*
205-L Same as -r. {only in some versions of Vi: "List recoverable
206 edit sessions"}
207
208 *-R*
209-R Readonly mode. The 'readonly' option will be set for all the
210 files being edited. You can still edit the buffer, but will
211 be prevented from accidentally overwriting a file. If you
212 forgot that you are in View mode and did make some changes,
213 you can overwrite a file by adding an exclamation mark to
214 the Ex command, as in ":w!". The 'readonly' option can be
215 reset with ":set noro" (see the options chapter, |options|).
216 Subsequent edits will not be done in readonly mode. Calling
217 the executable "view" has the same effect as the -R argument.
218 The 'updatecount' option will be set to 10000, meaning that
219 the swap file will not be updated automatically very often.
220
221 *-m*
222-m Modifications not allowed to be written. The 'write' option
223 will be reset, so that writing files is disabled. However,
224 the 'write' option can be set to enable writing again.
225 {not in Vi}
226
227 *-M*
228-M Modifications not allowed. The 'modifiable' option will be
229 reset, so that changes are not allowed. The 'write' option
230 will be reset, so that writing files is disabled. However,
231 the 'modifiable' and 'write' options can be set to enable
232 changes and writing.
233 {not in Vi}
234
235 *-Z* *restricted-mode* *E145*
236-Z Restricted mode. All commands that make use of an external
237 shell are disabled. This includes suspending with CTRL-Z,
238 ":sh", filtering, the system() function, backtick expansion,
239 etc.
240 {not in Vi}
241
242 *-g*
243-g Start Vim in GUI mode. See |gui|. {not in Vi}
244
245 *-v*
246-v Start Ex in Vi mode. Only makes a difference when the
247 executable is called "ex" or "gvim". For gvim the GUI is not
248 started if possible.
249
250 *-e*
251-e Start Vim in Ex mode |Q|. Only makes a difference when the
252 executable is not called "ex".
253
254 *-E*
255-E Start Vim in improved Ex mode |gQ|. Only makes a difference
256 when the executable is not called "exim".
257 {not in Vi}
258
259 *-s-ex*
260-s Silent or batch mode. Only when Vim was started as "ex" or
261 when preceded with the "-e" argument. Otherwise see |-s|,
262 which does take an argument while this use of "-s" doesn't.
263 To be used when Vim is used to execute Ex commands from a file
264 instead of a terminal. Switches off most prompts and
265 informative messages. Also warnings and error messages.
Bram Moolenaar26a60b42005-02-22 08:49:11 +0000266 The output of these commands is displayed (to stdout):
267 :print
268 :list
269 :number
270 :set to display option values.
271 When 'verbose' is non-zero messages are printed (for
272 debugging, to stderr).
273 'term' and $TERM are not used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274 If Vim appears to be stuck try typing "qa!<Enter>". You don't
275 get a prompt thus you can't see Vim is waiting for you to type
276 something.
277 Initializations are skipped (except the ones given with the
278 "-u" argument).
279 Example: >
280 vim -e -s < thefilter thefile
281<
282 *-b*
283-b Binary mode. File I/O will only recognize <NL> to separate
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000284 lines. The 'expandtab' option will be reset. The 'textwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285 option is set to 0. 'modeline' is reset. The 'binary' option
286 is set. This is done after reading the vimrc/exrc files but
287 before reading any file in the arglist. See also
288 |edit-binary|. {not in Vi}
289
290 *-l*
291-l Lisp mode. Sets the 'lisp' and 'showmatch' options on.
292
293 *-A*
294-A Arabic mode. Sets the 'arabic' option on. (Only when
295 compiled with the |+arabic| features (which include
296 |+rightleft|), otherwise Vim gives an error message
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000297 and exits.) {not in Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000298
299 *-F*
300-F Farsi mode. Sets the 'fkmap' and 'rightleft' options on.
301 (Only when compiled with |+rightleft| and |+farsi| features,
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000302 otherwise Vim gives an error message and exits.) {not in Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303
304 *-H*
305-H Hebrew mode. Sets the 'hkmap' and 'rightleft' options on.
306 (Only when compiled with the |+rightleft| feature, otherwise
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000307 Vim gives an error message and exits.) {not in Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308
309 *-V* *verbose*
310-V[N] Verbose. Sets the 'verbose' option to [N] (default: 10).
311 Messages will be given for each file that is ":source"d and
312 for reading or writing a viminfo file. Can be used to find
313 out what is happening upon startup and exit. {not in Vi}
314
315 *-D*
316-D Debugging. Go to debugging mode when executing the first
317 command from a script. |debug-mode|
318 {not available when compiled without the |+eval| feature}
319 {not in Vi}
320
321 *-C*
322-C Compatible mode. Sets the 'compatible' option. You can use
323 this to get 'compatible', even though a .vimrc file exists.
324 But the command ":set nocompatible" overrules it anyway.
325 Also see |compatible-default|. {not in Vi}
326
327 *-N*
328-N Not compatible mode. Resets the 'compatible' option. You can
329 use this to get 'nocompatible', when there is no .vimrc file.
330 Also see |compatible-default|. {not in Vi}
331
332 *-y* *easy*
333-y Easy mode. Implied for |evim| and |eview|. Starts with
334 'insertmode' set and behaves like a click-and-type editor.
335 This sources the script $VIMRUNTIME/evim.vim. Mappings are
336 set up to work like most click-and-type editors, see
337 |evim-keys|. The GUI is started when available.
338 {not in Vi}
339
340 *-n*
341-n No swap file will be used. Recovery after a crash will be
342 impossible. Handy if you want to view or edit a file on a
343 very slow medium (e.g., a floppy).
344 Can also be done with ":set updatecount=0". You can switch it
345 on again by setting the 'updatecount' option to some value,
346 e.g., ":set uc=100".
347 'updatecount' is set to 0 AFTER executing commands from a
348 vimrc file, but before the GUI initializations. Thus it
349 overrides a setting for 'updatecount' in a vimrc file, but not
350 in a gvimrc file. See |startup|.
351 When you want to reduce accesses to the disk (e.g., for a
352 laptop), don't use "-n", but set 'updatetime' and
353 'updatecount' to very big numbers, and type ":preserve" when
354 you want to save your work. This way you keep the possibility
355 for crash recovery.
356 {not in Vi}
357
358 *-o*
359-o[N] Open N windows, split horizontally. If [N] is not given,
360 one window is opened for every file given as argument. If
361 there is not enough room, only the first few files get a
362 window. If there are more windows than arguments, the last
363 few windows will be editing an empty file.
364 {not in Vi}
365
366 *-O*
367-O[N] Open N windows, split vertically. Otherwise it's like -o.
368 If both the -o and the -O option are given, the last one on
369 the command line determines how the windows will be split.
370 {not in Vi}
371
372 *-T*
373-T {terminal} Set the terminal type to "terminal". This influences the
374 codes that Vim will send to your terminal. This is normally
375 not needed, because Vim will be able to find out what type
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000376 of terminal you are using. (See |terminal-info|.) {not in Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377
378 *-d*
379-d Start in diff mode, like |vimdiff|.
380 {not in Vi} {not available when compiled without the |+diff|
381 feature}
382
383-d {device} Only on the Amiga and when not compiled with the |+diff|
384 feature. Works like "-dev".
385 *-dev*
386-dev {device} Only on the Amiga: The {device} is opened to be used for
387 editing.
388 Normally you would use this to set the window position and
389 size: "-d con:x/y/width/height", e.g.,
390 "-d con:30/10/600/150". But you can also use it to start
391 editing on another device, e.g., AUX:. {not in Vi}
392 *-f*
393-f Amiga: Do not restart Vim to open a new window. This
394 option should be used when Vim is started by a program that
395 will wait for the edit session to finish (e.g., mail or
396 readnews). See |amiga-window|.
397
398 GUI: Do not disconnect from the program that started Vim.
399 'f' stands for "foreground". If omitted, the GUI forks a new
400 process and exits the current one. "-f" should be used when
401 gvim is started by a program that will wait for the edit
402 session to finish (e.g., mail or readnews). If you want gvim
403 never to fork, include 'f' in 'guioptions' in your .gvimrc.
404 Careful: You can use "-gf" to start the GUI in the foreground,
405 but "-fg" is used to specify the foreground color. |gui-fork|
406 {not in Vi}
407
408 *--nofork*
409--nofork GUI: Do not fork. Same as |-f|.
410 *-u* *E282*
411-u {vimrc} The file {vimrc} is read for initializations. Most other
412 initializations are skipped; see |initialization|. This can
413 be used to start Vim in a special mode, with special
414 mappings and settings. A shell alias can be used to make
415 this easy to use. For example: >
416 alias vimc vim -u ~/.c_vimrc !*
417< Also consider using autocommands; see |autocommand|.
418 When {vimrc} is equal to "NONE" (all uppercase), all
419 initializations from files and environment variables are
420 skipped, including reading the .gvimrc file when the GUI
421 starts. Loading plugins is also skipped.
422 When {vimrc} is equal to "NORC" (all uppercase), this has the
423 same effect as "NONE", but loading plugins is not skipped.
424 Using the "-u" argument has the side effect that the
425 'compatible' option will be on by default. This can have
426 unexpected effects. See |'compatible'|.
427 {not in Vi}
428
429 *-U* *E230*
430-U {gvimrc} The file "gvimrc" is read for initializations when the GUI
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000431 starts. Other GUI initializations are skipped. When {gvimrc}
Bram Moolenaar8fc061c2004-12-29 21:03:02 +0000432 is equal to "NONE", no file is read for GUI initializations at
433 all. |gui-init|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000434 Exception: Reading the system-wide menu file is always done.
435 {not in Vi}
436
437 *-i*
438-i {viminfo} The file "viminfo" is used instead of the default viminfo
439 file. If the name "NONE" is used (all uppercase), no viminfo
440 file is read or written, even if 'viminfo' is set or when
441 ":rv" or ":wv" are used. See also |viminfo-file|.
442 {not in Vi}
443
444 *-x*
445-x Use encryption to read/write files. Will prompt for a key,
446 which is then stored in the 'key' option. All writes will
447 then use this key to encrypt the text. The '-x' argument is
448 not needed when reading a file, because there is a check if
449 the file that is being read has been encrypted, and Vim asks
450 for a key automatically. |encryption|
451
452 *-X*
453-X Do not try connecting to the X server to get the current
454 window title and copy/paste using the X clipboard. This
455 avoids a long startup time when running Vim in a terminal
456 emulator and the connection to the X server is slow.
457 Only makes a difference on Unix or VMS, when compiled with the
458 |+X11| feature. Otherwise it's ignored.
459 To disable the connection only for specific terminals, see the
460 'clipboard' option.
461 When the X11 Session Management Protocol (XSMP) handler has
462 been built in, the -X option also disables that connection as
463 it, too, may have undesirable delays.
464 When the connection is desired later anyway (e.g., for
465 client-server messages), call the |serverlist()| function.
466 This does not enable the XSMP handler though.
467 {not in Vi}
468
469 *-s*
470-s {scriptin} The script file "scriptin" is read. The characters in the
471 file are interpreted as if you had typed them. The same can
472 be done with the command ":source! {scriptin}". If the end
473 of the file is reached before the editor exits, further
474 characters are read from the keyboard. Only works when not
475 started in Ex mode, see |-s-ex|. See also |complex-repeat|.
476 {not in Vi}
477
Bram Moolenaar4399ef42005-02-12 14:29:27 +0000478 *-w_nr*
479-w {number}
480-w{number} Set the 'window' option to {number}.
481
Bram Moolenaar071d4272004-06-13 20:20:40 +0000482 *-w*
483-w {scriptout} All the characters that you type are recorded in the file
484 "scriptout", until you exit Vim. This is useful if you want
485 to create a script file to be used with "vim -s" or
486 ":source!". When the "scriptout" file already exists, new
487 characters are appended. See also |complex-repeat|.
Bram Moolenaar4399ef42005-02-12 14:29:27 +0000488 {scriptout} cannot start with a digit.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000489 {not in Vi}
490
491 *-W*
492-W {scriptout} Like -w, but do not append, overwrite an existing file.
493 {not in Vi}
494
Bram Moolenaar071d4272004-06-13 20:20:40 +0000495--remote [+{cmd}] {file} ...
496 Open the {file} in another Vim that functions as a server.
497 Any non-file arguments must come before this.
498 See |--remote|. {not in Vi}
499
500--remote-silent [+{cmd}] {file} ...
501 Like --remote, but don't complain if there is no server.
502 See |--remote-silent|. {not in Vi}
503
504--remote-wait [+{cmd}] {file} ...
505 Like --remote, but wait for the server to finish editing the
506 file(s).
507 See |--remote-wait|. {not in Vi}
508
509--remote-wait-silent [+{cmd}] {file} ...
510 Like --remote-wait, but don't complain if there is no server.
511 See |--remote-wait-silent|. {not in Vi}
512
513--servername {name}
514 Specify the name of the Vim server to send to or to become.
515 See |--servername|. {not in Vi}
516
517--remote-send {keys}
518 Send {keys} to a Vim server and exit.
519 See |--remote-send|. {not in Vi}
520
521--remote-expr {expr}
522 Evaluate {expr} in another Vim that functions as a server.
523 The result is printed on stdout.
524 See |--remote-expr|. {not in Vi}
525
526--serverlist Output a list of Vim server names and exit. See
527 See |--serverlist|. {not in Vi}
528
529--socketid {id} *--socketid*
530 GTK+ GUI Vim only. Make gvim try to use GtkPlug mechanism, so
531 that it runs inside another window. See |gui-gtk-socketid|
532 for details. {not in Vi}
533
534--echo-wid *--echo-wid*
535 GTK+ GUI Vim only. Make gvim echo the Window ID on stdout,
536 which can be used to run gvim in a kpart widget. The format
537 of the output is: >
538 WID: 12345\n
539< {not in Vi}
540
541--role {role} *--role*
542 GTK+ 2 GUI only. Set the role of the main window to {role}.
543 The window role can be used by a window manager to uniquely
544 identify a window, in order to restore window placement and
545 such. The --role argument is passed automatically when
546 restoring the session on login. See |gui-gnome-session|
547 {not in Vi}
548
549-P {parent-title} *-P* *MDI* *E671* *E672*
550 Win32 only: Specify the title of the parent application. When
551 possible, Vim will run in an MDI window inside the
552 application.
553 {parent-title} must appear in the window title of the parent
554 application. Make sure that it is specific enough.
555 Note that the implementation is still primitive. It won't
556 work with all applications and the menu doesn't work.
557
558-nb *-nb*
559-nb={fname}
560-nb:{hostname}:{addr}:{password}
561 Attempt connecting to Netbeans and become an editor server for
562 it. The second form specifies a file to read connection info
563 from. The third form specifies the hostname, address and
564 password for connecting to Netbeans. |netbeans-run|
565
566Example for using a script file to change a name in several files:
567 Create a file "subs.vi" containing substitute commands and a :wq
568 command: >
569 :%s/Jones/Smith/g
570 :%s/Allen/Peter/g
571 :wq
572<
573 Execute Vim on all files you want to change: >
574
575 foreach i ( *.let ) vim -s subs.vi $i
576
577If the executable is called "view", Vim will start in Readonly mode. This is
578useful if you can make a hard or symbolic link from "view" to "vim".
579Starting in Readonly mode can also be done with "vim -R".
580
581If the executable is called "ex", Vim will start in "Ex" mode. This means it
582will accept only ":" commands. But when the "-v" argument is given, Vim will
583start in Normal mode anyway.
584
585Additional arguments are available on unix like systems when compiled with
586X11 GUI support. See |gui-resources|.
587
588==============================================================================
5892. Vim on the Amiga *starting-amiga*
590
591Starting Vim from the Workbench *workbench*
592-------------------------------
593
594Vim can be started from the Workbench by clicking on its icon twice. It will
595then start with an empty buffer.
596
597Vim can be started to edit one or more files by using a "Project" icon. The
598"Default Tool" of the icon must be the full pathname of the Vim executable.
599The name of the ".info" file must be the same as the name of the text file.
600By clicking on this icon twice, Vim will be started with the file name as
601current file name, which will be read into the buffer (if it exists). You can
602edit multiple files by pressing the shift key while clicking on icons, and
603clicking twice on the last one. The "Default Tool" for all these icons must
604be the same.
605
606It is not possible to give arguments to Vim, other than file names, from the
607workbench.
608
609Vim window *amiga-window*
610----------
611
612Vim will run in the CLI window where it was started. If Vim was started with
613the "run" or "runback" command, or if Vim was started from the workbench, it
614will open a window of its own.
615
616Technical detail:
617 To open the new window a little trick is used. As soon as Vim
618 recognizes that it does not run in a normal CLI window, it will
619 create a script file in "t:". This script file contains the same
620 command as the one Vim was started with, and an "endcli" command.
621 This script file is then executed with a "newcli" command (the "c:run"
622 and "c:newcli" commands are required for this to work). The script
623 file will hang around until reboot, or until you delete it. This
624 method is required to get the ":sh" and ":!" commands to work
625 correctly. But when Vim was started with the -f option (foreground
626 mode), this method is not used. The reason for this is that
627 when a program starts Vim with the -f option it will wait for Vim to
628 exit. With the script trick, the calling program does not know when
629 Vim exits. The -f option can be used when Vim is started by a mail
630 program which also waits for the edit session to finish. As a
631 consequence, the ":sh" and ":!" commands are not available when the
632 -f option is used.
633
634Vim will automatically recognize the window size and react to window
635resizing. Under Amiga DOS 1.3, it is advised to use the fastfonts program,
636"FF", to speed up display redrawing.
637
638==============================================================================
6393. Running eVim *evim-keys*
640
641EVim runs Vim as click-and-type editor. This is very unlike the original Vi
642idea. But it helps for people that don't use Vim often enough to learn the
643commands. Hopefully they will find out that learning to use Normal mode
644commands will make their editing much more effective.
645
646In Evim these options are changed from their default value:
647
648 :set nocompatible Use Vim improvements
649 :set insertmode Remain in Insert mode most of the time
650 :set hidden Keep invisible buffers loaded
651 :set backup Keep backup files (not for VMS)
652 :set backspace=2 Backspace over everything
653 :set autoindent auto-indent new lines
654 :set history=50 keep 50 lines of Ex commands
655 :set ruler show the cursor position
656 :set incsearch show matches halfway typing a pattern
657 :set mouse=a use the mouse in all modes
658 :set hlsearch highlight all matches for a search pattern
659 :set whichwrap+=<,>,[,] <Left> and <Right> wrap around line breaks
660 :set guioptions-=a non-Unix only: don't do auto-select
661
662Key mappings:
663 <Down> moves by screen lines rather than file lines
664 <Up> idem
665 Q does "gq", formatting, instead of Ex mode
666 <BS> in Visual mode: deletes the selection
667 CTRL-X in Visual mode: Cut to clipboard
668 <S-Del> idem
669 CTRL-C in Visual mode: Copy to clipboard
670 <C-Insert> idem
671 CTRL-V Pastes from the clipboard (in any mode)
672 <S-Insert> idem
673 CTRL-Q do what CTRL-V used to do
674 CTRL-Z undo
675 CTRL-Y redo
676 <M-Space> system menu
677 CTRL-A select all
678 <C-Tab> next window, CTRL-W w
679 <C-F4> close window, CTRL-W c
680
681Additionally:
682- ":behave mswin" is used |:behave|
683- syntax highlighting is enabled
684- filetype detection is enabled, filetype plugins and indenting is enabled
685- in a text file 'textwidth' is set to 78
686
687One hint: If you want to go to Normal mode to be able to type a sequence of
688commands, use CTRL-L. |i_CTRL-L|
689
690==============================================================================
6914. Initialization *initialization* *startup*
692
693This section is about the non-GUI version of Vim. See |gui-fork| for
694additional initialization when starting the GUI.
695
696At startup, Vim checks environment variables and files and sets values
697accordingly. Vim proceeds in this order:
698
6991. Set the 'shell' and 'term' option *SHELL* *COMSPEC* *TERM*
700 The environment variable SHELL, if it exists, is used to set the
701 'shell' option. On MS-DOS and Win32, the COMSPEC variable is used
702 if SHELL is not set.
703 The environment variable TERM, if it exists, is used to set the 'term'
704 option.
705
7062. Process the arguments
707 The options and file names from the command that start Vim are
708 inspected. Buffers are created for all files (but not loaded yet).
709
7103. Execute Ex commands, from environment variables and/or files
711 An environment variable is read as one Ex command line, where multiple
712 commands must be separated with '|' or "<NL>".
713 *vimrc* *exrc*
714 A file that contains initialization commands is called a "vimrc" file.
715 Each line in a vimrc file is executed as an Ex command line. It is
716 sometimes also referred to as "exrc" file. They are the same type of
717 file, but "exrc" is what Vi always used, "vimrc" is a Vim specific
718 name. Also see |vimrc-intro|.
719
720 Recommended place for your personal initializations:
721 Unix $HOME/.vimrc
722 OS/2 $HOME/.vimrc or $VIM/.vimrc (or _vimrc)
723 MS-DOS and Win32 $HOME/_vimrc or $VIM/_vimrc
724 Amiga s:.vimrc or $VIM/.vimrc
725
726 If Vim was started with "-u filename", the file "filename" is used.
727 All following initializations until 4. are skipped.
728 "vim -u NORC" can be used to skip these initializations without
729 reading a file. "vim -u NONE" also skips loading plugins. |-u|
730
731 If Vim was started in Ex mode with the "-s" argument, all following
732 initializations until 4. are skipped. Only the "-u" option is
733 interpreted.
734 *evim.vim*
735 a. If vim was started as |evim| or |eview| or with the |-y| argument, the
736 script $VIMRUNTIME/evim.vim will be loaded.
737 *system-vimrc*
738 b. For Unix, MS-DOS, MS-Windows, OS/2, VMS, Macintosh, RISC-OS and Amiga
739 the system vimrc file is read for initializations. The path of this
740 file is shown with the ":version" command. Mostly it's "$VIM/vimrc".
741 Note that this file is ALWAYS read in 'compatible' mode, since the
742 automatic resetting of 'compatible' is only done later. Add a ":set
743 nocp" command if you like.
744
745 *VIMINIT* *.vimrc* *_vimrc* *EXINIT* *.exrc* *_exrc*
746 c. Four places are searched for initializations. The first that exists
747 is used, the others are ignored.
748 - The environment variable VIMINIT (see also |compatible-default|) (*)
749 The value of $VIMINIT is used as an Ex command line.
750 - The user vimrc file(s):
751 "$HOME/.vimrc" (for Unix and OS/2) (*)
752 "s:.vimrc" (for Amiga) (*)
753 "home:.vimrc" (for Amiga) (*)
754 "$VIM/.vimrc" (for OS/2 and Amiga) (*)
755 "$HOME/_vimrc" (for MS-DOS and Win32) (*)
Bram Moolenaar21cf8232004-07-16 20:18:37 +0000756 "$VIM/_vimrc" (for MS-DOS and Win32) (*)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 Note: For Unix, OS/2 and Amiga, when ".vimrc" does not exist,
758 "_vimrc" is also tried, in case an MS-DOS compatible file
759 system is used. For MS-DOS and Win32 ".vimrc" is checked
760 after "_vimrc", in case long file names are used.
761 Note: For MS-DOS and Win32, "$HOME" is checked first. If no
762 "_vimrc" or ".vimrc" is found there, "$VIM" is tried.
763 See |$VIM| for when $VIM is not set.
764 - The environment variable EXINIT.
765 The value of $EXINIT is used as an Ex command line.
766 - The user exrc file(s). Same as for the user vimrc file, but with
Bram Moolenaar5c5474b2005-04-19 21:40:26 +0000767 "vimrc" replaced by "exrc". But only one of ".exrc" and "_exrc" is
768 used, depending on the system. And without the (*)!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769
770 d. If the 'exrc' option is on (which is not the default), the current
Bram Moolenaar5c5474b2005-04-19 21:40:26 +0000771 directory is searched for three files. The first that exists is used,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772 the others are ignored.
773 - The file ".vimrc" (for Unix, Amiga and OS/2) (*)
774 "_vimrc" (for MS-DOS and Win32) (*)
775 - The file "_vimrc" (for Unix, Amiga and OS/2) (*)
776 ".vimrc" (for MS-DOS and Win32) (*)
777 - The file ".exrc" (for Unix, Amiga and OS/2)
778 "_exrc" (for MS-DOS and Win32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000779
780 (*) Using this file or environment variable will cause 'compatible' to be
781 off by default. See |compatible-default|.
782
7834. Load the plugin scripts. *load-plugins*
784 This does the same as the command: >
785 :runtime! plugin/*.vim
786< The result is that all directories in the 'runtimepath' option will be
787 searched for the "plugin" sub-directory and all files ending in ".vim"
788 will be sourced (in alphabetical order per directory).
789 Loading plugins won't be done when:
790 - The 'loadplugins' option was reset in a vimrc file.
791 - The |--noplugin| command line argument is used.
792 - The "-u NONE" command line argument is used |-u|.
793 - When Vim was compiled without the |+eval| feature.
794 Note that using "-c set noloadplugins" doesn't work, because the
795 commands from the command line have not been executed yet.
796
7975. Set 'shellpipe' and 'shellredir'
798 The 'shellpipe' and 'shellredir' options are set according to the
799 value of the 'shell' option, unless they have been set before.
800 This means that Vim will figure out the values of 'shellpipe' and
801 'shellredir' for you, unless you have set them yourself.
802
8036. Set 'updatecount' to zero, if "-n" command argument used
804
8057. Set binary options
806 If the "-b" flag was given to Vim, the options for binary editing will
807 be set now. See |-b|.
808
8098. Perform GUI initializations
810 Only when starting "gvim", the GUI initializations will be done. See
811 |gui-init|.
812
8139. Read the viminfo file
814 If the 'viminfo' option is not empty, the viminfo file is read. See
815 |viminfo-file|.
816
81710. Read the quickfix file
818 If the "-q" flag was given to Vim, the quickfix file is read. If this
819 fails, Vim exits.
820
82111. Open all windows
822 When the |-o| flag was given, windows will be opened (but not
823 displayed yet).
824 When switching screens, it happens now. Redrawing starts.
825 If the "-q" flag was given to Vim, the first error is jumped to.
826 Buffers for all windows will be loaded.
827
82812. Execute startup commands
829 If a "-t" flag was given to Vim, the tag is jumped to.
830 The commands given with the |-c| and |+cmd| arguments are executed.
831 If the 'insertmode' option is set, Insert mode is entered.
832 The |VimEnter| autocommands are executed.
833
834Some hints on using initializations:
835
836Standard setup:
837Create a vimrc file to set the default settings and mappings for all your edit
838sessions. Put it in a place so that it will be found by 3b:
839 ~/.vimrc (Unix and OS/2)
840 s:.vimrc (Amiga)
841 $VIM\_vimrc (MS-DOS and Win32)
842Note that creating a vimrc file will cause the 'compatible' option to be off
843by default. See |compatible-default|.
844
845Local setup:
846Put all commands that you need for editing a specific directory only into a
847vimrc file and place it in that directory under the name ".vimrc" ("_vimrc"
848for MS-DOS and Win32). NOTE: To make Vim look for these special files you
849have to turn on the option 'exrc'. See |trojan-horse| too.
850
851System setup:
852This only applies if you are managing a Unix system with several users and
853want to set the defaults for all users. Create a vimrc file with commands
854for default settings and mappings and put it in the place that is given with
855the ":version" command.
856
857Saving the current state of Vim to a file:
858Whenever you have changed values of options or when you have created a
859mapping, then you may want to save them in a vimrc file for later use. See
860|save-settings| about saving the current state of settings to a file.
861
862Avoiding setup problems for Vi users:
863Vi uses the variable EXINIT and the file "~/.exrc". So if you do not want to
864interfere with Vi, then use the variable VIMINIT and the file "vimrc" instead.
865
866Amiga environment variables:
867On the Amiga, two types of environment variables exist. The ones set with the
868DOS 1.3 (or later) setenv command are recognized. See the AmigaDos 1.3
869manual. The environment variables set with the old Manx Set command (before
870version 5.0) are not recognized.
871
872MS-DOS line separators:
873On MS-DOS-like systems (MS-DOS itself, Win32, and OS/2), Vim assumes that all
874the vimrc files have <CR> <NL> pairs as line separators. This will give
875problems if you have a file with only <NL>s and have a line like
876":map xx yy^M". The trailing ^M will be ignored.
877
878 *compatible-default*
879When Vim starts, the 'compatible' option is on. This will be used when Vim
880starts its initializations. But as soon as a user vimrc file is found, or a
881vimrc file in the current directory, or the "VIMINIT" environment variable is
882set, it will be set to 'nocompatible'. This has the side effect of setting or
883resetting other options (see 'compatible'). But only the options that have
884not been set or reset will be changed. This has the same effect like the
885value of 'compatible' had this value when starting Vim. Note that this
886doesn't happen for the system-wide vimrc file.
887
888But there is a side effect of setting or resetting 'compatible' at the moment
889a .vimrc file is found: Mappings are interpreted the moment they are
890encountered. This makes a difference when using things like "<CR>". If the
891mappings depend on a certain value of 'compatible', set or reset it before
892giving the mapping.
893
894The above behavior can be overridden in these ways:
895- If the "-N" command line argument is given, 'nocompatible' will be used,
896 even when no vimrc file exists.
897- If the "-C" command line argument is given, 'compatible' will be used, even
898 when a vimrc file exists.
899- If the "-u {vimrc}" argument is used, 'compatible' will be used.
900- When the name of the executable ends in "ex", then this works like the "-C"
901 argument was given: 'compatible' will be used, even when a vimrc file
902 exists. This has been done to make Vim behave like "ex", when it is started
903 as "ex".
904
905Avoiding trojan horses: *trojan-horse*
906While reading the "vimrc" or the "exrc" file in the current directory, some
907commands can be disabled for security reasons by setting the 'secure' option.
908This is always done when executing the command from a tags file. Otherwise it
909would be possible that you accidentally use a vimrc or tags file that somebody
910else created and contains nasty commands. The disabled commands are the ones
911that start a shell, the ones that write to a file, and ":autocmd". The ":map"
912commands are echoed, so you can see which keys are being mapped.
913 If you want Vim to execute all commands in a local vimrc file, you
914can reset the 'secure' option in the EXINIT or VIMINIT environment variable or
915in the global "exrc" or "vimrc" file. This is not possible in "vimrc" or
916"exrc" in the current directory, for obvious reasons.
917 On Unix systems, this only happens if you are not the owner of the
918vimrc file. Warning: If you unpack an archive that contains a vimrc or exrc
919file, it will be owned by you. You won't have the security protection. Check
920the vimrc file before you start Vim in that directory, or reset the 'exrc'
921option. Some Unix systems allow a user to do "chown" on a file. This makes
922it possible for another user to create a nasty vimrc and make you the owner.
923Be careful!
924 When using tag search commands, executing the search command (the last
925part of the line in the tags file) is always done in secure mode. This works
926just like executing a command from a vimrc/exrc in the current directory.
927
928 *slow-start*
929If Vim takes a long time to start up, there may be a few causes:
930- If the Unix version was compiled with the GUI and/or X11 (check the output
931 of ":version" for "+GUI" and "+X11"), it may need to load shared libraries
932 and connect to the X11 server. Try compiling a version with GUI and X11
933 disabled. This also should make the executable smaller.
934 Use the |-X| command line argument to avoid connecting to the X server when
935 running in a terminal.
936- If you have "viminfo" enabled, the loading of the viminfo file may take a
937 while. You can find out if this is the problem by disabling viminfo for a
938 moment (use the Vim argument "-i NONE", |-i|). Try reducing the number of
939 lines stored in a register with ":set viminfo='20,<50,s10". |viminfo-file|.
940
941 *:intro*
942When Vim starts without a file name, an introductory message is displayed (for
943those who don't know what Vim is). It is removed as soon as the display is
944redrawn in any way. To see the message again, use the ":intro" command (if
945there is not enough room, you will see only part of it).
946 To avoid the intro message on startup, add the 'I' flag to 'shortmess'.
947
948 *info-message*
949The |--help| and |--version| arguments cause Vim to print a message and then
950exit. Normally the message is send to stdout, thus can be redirected to a
951file with: >
952
953 vim --help >file
954
955From inside Vim: >
956
957 :read !vim --help
958
959When using gvim, it detects that it might have been started from the desktop,
960without a terminal to show messages on. This is detected when both stdout and
961stderr are not a tty. This breaks the ":read" command, as used in the example
962above. To make it work again, set 'shellredir' to ">" instead of the default
963">&": >
964
965 :set shellredir=>
966 :read !gvim --help
967
968This still won't work for systems where gvim does not use stdout at all
969though.
970
971==============================================================================
9725. $VIM and $VIMRUNTIME
973 *$VIM*
974The environment variable "$VIM" is used to locate various user files for Vim,
975such as the user startup script ".vimrc". This depends on the system, see
976|startup|.
977
978To avoid the need for every user to set the $VIM environment variable, Vim
979will try to get the value for $VIM in this order:
9801. The value defined by the $VIM environment variable. You can use this to
981 make Vim look in a specific directory for its support files. Example: >
982 setenv VIM /home/paul/vim
9832. The path from 'helpfile' is used, unless it contains some environment
984 variable too (the default is "$VIMRUNTIME/doc/help.txt": chicken-egg
985 problem). The file name ("help.txt" or any other) is removed. Then
986 trailing directory names are removed, in this order: "doc", "runtime" and
987 "vim{version}" (e.g., "vim54").
9883. For MSDOS, Win32 and OS/2 Vim tries to use the directory name of the
989 executable. If it ends in "/src", this is removed. This is useful if you
990 unpacked the .zip file in some directory, and adjusted the search path to
991 find the vim executable. Trailing directory names are removed, in this
992 order: "runtime" and "vim{version}" (e.g., "vim54").
9934. For Unix the compile-time defined installation directory is used (see the
994 output of ":version").
995
996Once Vim has done this once, it will set the $VIM environment variable. To
997change it later, use a ":let" command like this: >
998 :let $VIM = "/home/paul/vim/"
999<
1000 *$VIMRUNTIME*
1001The environment variable "$VIMRUNTIME" is used to locate various support
1002files, such as the on-line documentation and files used for syntax
1003highlighting. For example, the main help file is normally
1004"$VIMRUNTIME/doc/help.txt".
1005You don't normally set $VIMRUNTIME yourself, but let Vim figure it out. This
1006is the order used to find the value of $VIMRUNTIME:
10071. If the environment variable $VIMRUNTIME is set, it is used. You can use
1008 this when the runtime files are in an unusual location.
10092. If "$VIM/vim{version}" exists, it is used. {version} is the version
1010 number of Vim, without any '-' or '.'. For example: "$VIM/vim54". This is
1011 the normal value for $VIMRUNTIME.
10123. If "$VIM/runtime" exists, it is used.
10134. The value of $VIM is used. This is for backwards compatibility with older
1014 versions.
10155. When the 'helpfile' option is set and doesn't contain a '$', its value is
1016 used, with "doc/help.txt" removed from the end.
1017
1018For Unix, when there is a compiled-in default for $VIMRUNTIME (check the
1019output of ":version"), steps 2, 3 and 4 are skipped, and the compiled-in
1020default is used after step 5. This means that the compiled-in default
1021overrules the value of $VIM. This is useful if $VIM is "/etc" and the runtime
1022files are in "/usr/share/vim/vim54".
1023
1024Once Vim has done this once, it will set the $VIMRUNTIME environment variable.
1025To change it later, use a ":let" command like this: >
1026 :let $VIMRUNTIME = "/home/piet/vim/vim54"
1027
Bram Moolenaared203462004-06-16 11:19:22 +00001028In case you need the value of $VIMRUNTIME in a shell (e.g., for a script that
1029greps in the help files) you might be able to use this: >
1030
1031 VIMRUNTIME=`vim -e -T dumb --cmd 'exe "set t_cm=\<C-M>"|echo $VIMRUNTIME|quit' | tr -d '\015' `
1032
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033==============================================================================
10346. Suspending *suspend*
1035
1036 *iconize* *iconise* *CTRL-Z* *v_CTRL-Z*
1037CTRL-Z Suspend Vim, like ":stop".
1038 Works in Normal and in Visual mode. In Insert and
1039 Command-line mode, the CTRL-Z is inserted as a normal
1040 character. In Visual mode Vim goes back to Normal
1041 mode.
Bram Moolenaar0d660222005-01-07 21:51:51 +00001042 Note: if CTRL-Z undoes a change see |mswin.vim|.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043
1044
1045:sus[pend][!] or *:sus* *:suspend* *:st* *:stop*
1046:st[op][!] Suspend Vim.
1047 If the '!' is not given and 'autowrite' is set, every
1048 buffer with changes and a file name is written out.
1049 If the '!' is given or 'autowrite' is not set, changed
1050 buffers are not written, don't forget to bring Vim
1051 back to the foreground later!
1052
1053In the GUI, suspending is implemented as iconising gvim. In Windows 95/NT,
1054gvim is minimized.
1055
1056On many Unix systems, it is possible to suspend Vim with CTRL-Z. This is only
1057possible in Normal and Visual mode (see next chapter, |vim-modes|). Vim will
1058continue if you make it the foreground job again. On other systems, CTRL-Z
1059will start a new shell. This is the same as the ":sh" command. Vim will
1060continue if you exit from the shell.
1061
1062In X-windows the selection is disowned when Vim suspends. this means you
1063can't paste it in another application (since Vim is going to sleep an attempt
1064to get the selection would make the program hang).
1065
1066==============================================================================
10677. Saving settings *save-settings*
1068
1069Mostly you will edit your vimrc files manually. This gives you the greatest
1070flexibility. There are a few commands to generate a vimrc file automatically.
1071You can use these files as they are, or copy/paste lines to include in another
1072vimrc file.
1073
1074 *:mk* *:mkexrc*
1075:mk[exrc] [file] Write current key mappings and changed options to
1076 [file] (default ".exrc" in the current directory),
1077 unless it already exists. {not in Vi}
1078
1079:mk[exrc]! [file] Always write current key mappings and changed
1080 options to [file] (default ".exrc" in the current
1081 directory). {not in Vi}
1082
1083 *:mkv* *:mkvimrc*
1084:mkv[imrc][!] [file] Like ":mkexrc", but the default is ".vimrc" in the
1085 current directory. The ":version" command is also
1086 written to the file. {not in Vi}
1087
1088These commands will write ":map" and ":set" commands to a file, in such a way
1089that when these commands are executed, the current key mappings and options
1090will be set to the same values. The options 'columns', 'endofline',
1091'fileformat', 'key', 'lines', 'modified', 'scroll', 'term', 'textmode',
1092'ttyfast' and 'ttymouse' are not included, because these are terminal or file
1093dependent. Note that the options 'binary', 'paste' and 'readonly' are
1094included, this might not always be what you want.
1095
1096When special keys are used in mappings, The 'cpoptions' option will be
1097temporarily set to its Vim default, to avoid the mappings to be
1098misinterpreted. This makes the file incompatible with Vi, but makes sure it
1099can be used with different terminals.
1100
1101Only global mappings are stored, not mappings local to a buffer.
1102
1103A common method is to use a default ".vimrc" file, make some modifications
1104with ":map" and ":set" commands and write the modified file. First read the
1105default ".vimrc" in with a command like ":source ~piet/.vimrc.Cprogs", change
1106the settings and then save them in the current directory with ":mkvimrc!". If
1107you want to make this file your default .vimrc, move it to your home directory
1108(on Unix), s: (Amiga) or $VIM directory (MS-DOS). You could also use
1109autocommands |autocommand| and/or modelines |modeline|.
1110
1111If you only want to add a single option setting to your vimrc, you can use
1112these steps:
11131. Edit your vimrc file with Vim.
11142. Play with the option until it's right. E.g., try out different values for
1115 'guifont'.
11163. Append a line to set the value of the option, using the expression register
1117 '=' to enter the value. E.g., for the 'guifont' option: >
1118 o:set guifont=<C-R>=&guifont<CR><Esc>
1119< [<C-R> is a CTRL-R, <CR> is a return, <Esc> is the escape key]
1120
1121Note that when you create a .vimrc file, this can influence the 'compatible'
1122option, which has several side effects. See |'compatible'|.
1123":mkvimrc", ":mkexrc" and ":mksession" write the command to set or reset the
1124'compatible' option to the output file first, because of these side effects.
1125
1126==============================================================================
11278. Views and Sessions *views-sessions*
1128
1129This is introduced in sections |21.4| and |21.5| of the user manual.
1130
1131 *View* *view-file*
1132A View is a collection of settings that apply to one window. You can save a
1133View and when you restore it later, the text is displayed in the same way.
1134The options and mappings in this window will also be restored, so that you can
1135continue editing like when the View was saved.
1136
1137 *Session* *session-file*
1138A Session keeps the Views for all windows, plus the global settings. You can
1139save a Session and when you restore it later the window layout looks the same.
1140You can use a Session to quickly switch between different projects,
1141automatically loading the files you were last working on in that project.
1142
1143Views and Sessions are a nice addition to viminfo-files, which are used to
1144remember information for all Views and Sessions together |viminfo-file|.
1145
1146You can quickly start editing with a previously saved View or Session with the
1147|-S| argument: >
1148 vim -S Session.vim
1149<
1150All this is {not in Vi} and {not available when compiled without the
1151|+mksession| feature}.
1152
1153 *:mks* *:mksession*
1154:mks[ession][!] [file] Write a Vim script that restores the current editing
1155 session.
1156 When [!] is included an existing file is overwritten.
1157 When [file] is omitted "Session.vim" is used.
1158
1159The output of ":mksession" is like ":mkvimrc", but additional commands are
1160added to the file. Which ones depends on the 'sessionoptions' option. The
1161resulting file, when executed with a ":source" command:
11621. Restores global mappings and options, if 'sessionoptions' contains
1163 "options". Script-local mappings will not be written.
11642. Restores global variables that start with an uppercase letter and contain
1165 at least one lowercase letter, if 'sessionoptions' contains "globals".
11663. Unloads all currently loaded buffers.
11674. Restores the current directory if 'sessionoptions' contains "curdir", or
1168 sets the current directory to where the Session file is if 'sessionoptions'
1169 contains "sesdir".
11705. Restores GUI Vim window position, if 'sessionoptions' contains "winpos".
11716. Restores screen size, if 'sessionoptions' contains "resize".
11727. Reloads the buffer list, with the last cursor positions. If
1173 'sessionoptions' contains "buffers" then all buffers are restored,
1174 including hidden and unloaded buffers. Otherwise only buffers in windows
1175 are restored.
11768. Restores all windows with the same layout. If 'sessionoptions' contains
1177 contains "help", help windows are restored. If 'sessionoptions' contains
1178 "blank", windows editing a buffer without a name will be restored.
1179 If 'sessionoptions' contains "winsize" and no (help/blank) windows were
1180 left out, the window sizes are restored (relative to the screen size).
1181 Otherwise, the windows are just given sensible sizes.
11829. Restores the Views for all the windows, as with |:mkview|. But
1183 'sessionoptions' is used instead of 'viewoptions'.
118410. If a file exists with the same name as the Session file, but ending in
1185 "x.vim" (for eXtra), executes that as well. You can use *x.vim files to
1186 specify additional settings and actions associated with a given Session,
1187 such as creating menu items in the GUI version.
1188
1189After restoring the Session, the full filename of your current Session is
1190available in the internal variable "v:this_session" |this_session-variable|.
1191An example mapping: >
1192 :nmap <F2> :wa<Bar>exe "mksession! " . v:this_session<CR>:so ~/sessions/
1193This saves the current Session, and starts off the command to load another.
1194
1195 *:mkvie* *:mkview*
1196:mkvie[w][!] [file] Write a Vim script that restores the contents of the
1197 current window.
1198 When [!] is included an existing file is overwritten.
1199 When [file] is omitted or is a number from 1 to 9, a
1200 name is generated and 'viewdir' prepended. When last
1201 directory name in 'viewdir' does not exist, this
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001202 directory is created. *E739*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203 An existing file is always overwritten then. Use
1204 |:loadview| to load this view again.
1205 When [file] is the name of a file ('viewdir' is not
1206 used), a command to edit the file is added to the
1207 generated file.
1208
1209The output of ":mkview" contains these items:
12101. The argument list used in the window. When the global argument list is
1211 used it is reset to the global list.
1212 The index in the argument list is also restored.
12132. The file being edited in the window. If there is no file, the window is
1214 made empty.
12153. Restore mappings, abbreviations and options local to the window if
1216 'viewoptions' contains "options" or "localoptions". For the options it
1217 restores only values that are local to the current buffer and values local
1218 to the window.
1219 When storing the view as part of a session and "options" is in
1220 'sessionoptions', global values for local options will be stored too.
12214. Restore folds when using manual folding and 'viewoptions' contains
1222 "folds". Restore manually opened and closed folds.
12235. The scroll position and the cursor position in the file. Doesn't work very
1224 well when there are closed folds.
12256. The local current directory, if it is different from the global current
1226 directory.
1227
1228Note that Views and Sessions are not perfect:
1229- They don't restore everything. For example, defined functions, autocommands
1230 and ":syntax on" are not included. Things like register contents and
1231 command line history are in viminfo, not in Sessions or Views.
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001232- Global option values are only set when they differ from the default value.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233 When the current value is not the default value, loading a Session will not
1234 set it back to the default value. Local options will be set back to the
1235 default value though.
1236- Existing mappings will be overwritten without warning. An existing mapping
1237 may cause an error for ambiguity.
1238- When storing manual folds and when storing manually opened/closed folds,
1239 changes in the file between saving and loading the view will mess it up.
1240- The Vim script is not very efficient. But still faster than typing the
1241 commands yourself!
1242
1243 *:lo* *:loadview*
1244:lo[adview] [nr] Load the view for the current file. When [nr] is
1245 omitted, the view stored with ":mkview" is loaded.
1246 When [nr] is specified, the view stored with ":mkview
1247 [nr]" is loaded.
1248
1249The combination of ":mkview" and ":loadview" can be used to store up to ten
1250different views of a file. These are remembered in the directory specified
1251with the 'viewdir' option. The views are stored using the file name. If a
1252file is renamed or accessed through a (symbolic) link the view will not be
1253found.
1254
1255You might want to clean up your 'viewdir' directory now and then.
1256
1257To automatically save and restore views for *.c files: >
1258 au BufWinLeave *.c mkview
1259 au BufWinEnter *.c silent loadview
1260
1261==============================================================================
12629. The viminfo file *viminfo* *viminfo-file* *E136*
1263 *E575* *E576* *E577*
1264If you exit Vim and later start it again, you would normally lose a lot of
1265information. The viminfo file can be used to remember that information, which
1266enables you to continue where you left off.
1267
1268This is introduced in section |21.3| of the user manual.
1269
1270The viminfo file is used to store:
1271- The command line history.
1272- The search string history.
1273- The input-line history.
Bram Moolenaar49cd9572005-01-03 21:06:01 +00001274- Contents of non-empty registers.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001275- Marks for several files.
1276- File marks, pointing to locations in files.
1277- Last search/substitute pattern (for 'n' and '&').
1278- The buffer list.
1279- Global variables.
1280
1281The viminfo file is not supported when the |+viminfo| feature has been
1282disabled at compile time.
1283
1284You could also use a Session file. The difference is that the viminfo file
1285does not depend on what you are working on. There normally is only one
1286viminfo file. Session files are used to save the state of a specific editing
1287Session. You could have several Session files, one for each project you are
1288working on. Viminfo and Session files together can be used to effectively
1289enter Vim and directly start working in your desired setup. |session-file|
1290
1291 *viminfo-read*
1292When Vim is started and the 'viminfo' option is non-empty, the contents of
1293the viminfo file are read and the info can be used in the appropriate places.
1294The marks are not read in at startup (but file marks are). See
1295|initialization| for how to set the 'viminfo' option upon startup.
1296
1297 *viminfo-write*
1298When Vim exits and 'viminfo' is non-empty, the info is stored in the viminfo
1299file (it's actually merged with the existing one, if one exists). The
1300'viminfo' option is a string containing information about what info should be
1301stored, and contains limits on how much should be stored (see 'viminfo').
1302
1303Notes for Unix:
1304- The file protection for the viminfo file will be set to prevent other users
1305 from being able to read it, because it may contain any text or commands that
1306 you have worked with.
1307- If you want to share the viminfo file with other users (e.g. when you "su"
1308 to another user), you can make the file writable for the group or everybody.
1309 Vim will preserve this when writing new viminfo files. Be careful, don't
1310 allow just anybody to read and write your viminfo file!
1311- Vim will not overwrite a viminfo file that is not writable by the current
1312 "real" user. This helps for when you did "su" to become root, but your
1313 $HOME is still set to a normal user's home directory. Otherwise Vim would
1314 create a viminfo file owned by root that nobody else can read.
1315
1316Marks are stored for each file separately. When a file is read and 'viminfo'
1317is non-empty, the marks for that file are read from the viminfo file. NOTE:
1318The marks are only written when exiting Vim, which is fine because marks are
1319remembered for all the files you have opened in the current editing session,
1320unless ":bdel" is used. If you want to save the marks for a file that you are
1321about to abandon with ":bdel", use ":wv". The '[' and ']' marks are not
1322stored, but the '"' mark is. The '"' mark is very useful for jumping to the
1323cursor position when the file was last exited. No marks are saved for files
1324that start with any string given with the "r" flag in 'viminfo'. This can be
1325used to avoid saving marks for files on removable media (for MS-DOS you would
1326use "ra:,rb:", for Amiga "rdf0:,rdf1:,rdf2:").
1327
1328 *viminfo-file-marks*
1329Uppercase marks ('A to 'Z) are stored when writing the viminfo file. The
1330numbered marks ('0 to '9) are a bit special. When the viminfo file is written
1331(when exiting or with the ":wviminfo" command), '0 is set to the current cursor
1332position and file. The old '0 is moved to '1, '1 to '2, etc. This
1333resembles what happens with the "1 to "9 delete registers. If the current
1334cursor position is already present in '0 to '9, it is moved to '0, to avoid
1335having the same position twice. The result is that with "'0", you can jump
1336back to the file and line where you exited Vim. To do that right away, try
1337using this command: >
1338
1339 vim -c "normal '0"
1340
1341In a shell you could make an alias for it: >
1342
1343 alias lvim vim -c '"'normal "'"0'"'
1344
1345Use the "r" flag in 'viminfo' to specify for which files no marks should be
1346remembered.
1347
1348
1349VIMINFO FILE NAME *viminfo-file-name*
1350
1351- The default name of the viminfo file is "$HOME/.viminfo" for Unix and OS/2,
1352 "s:.viminfo" for Amiga, "$HOME\_viminfo" for MS-DOS and Win32. For the last
1353 two, when $HOME is not set, "$VIM\_viminfo" is used. When $VIM is also not
1354 set, "c:\_viminfo" is used. For OS/2 "$VIM/.viminfo" is used when $HOME is
1355 not set and $VIM is set.
1356- The 'n' flag in the 'viminfo' option can be used to specify another viminfo
1357 file name |'viminfo'|.
1358- The "-i" Vim argument can be used to set another file name, |-i|. When the
1359 file name given is "NONE" (all uppercase), no viminfo file is ever read or
1360 written. Also not for the commands below!
1361- For the commands below, another file name can be given, overriding the
1362 default and the name given with 'viminfo' or "-i" (unless it's NONE).
1363
1364
1365CHARACTER ENCODING *viminfo-encoding*
1366
1367The text in the viminfo file is encoded as specified with the 'encoding'
1368option. Normally you will always work with the same 'encoding' value, and
1369this works just fine. However, if you read the viminfo file with another
1370value for 'encoding' than what it was written with, some of the text
1371(non-ASCII characters) may be invalid. If this is unacceptable, add the 'c'
1372flag to the 'viminfo' option: >
1373 :set viminfo+=c
1374Vim will then attempt to convert the text in the viminfo file from the
1375'encoding' value it was written with to the current 'encoding' value. This
1376requires Vim to be compiled with the |+iconv| feature. Filenames are not
1377converted.
1378
1379
1380MANUALLY READING AND WRITING
1381
1382Two commands can be used to read and write the viminfo file manually. This
1383can be used to exchange registers between two running Vim programs: First
1384type ":wv" in one and then ":rv" in the other. Note that if the register
1385already contained something, then ":rv!" would be required. Also note
1386however that this means everything will be overwritten with information from
1387the first Vim, including the command line history, etc.
1388
1389The viminfo file itself can be edited by hand too, although we suggest you
1390start with an existing one to get the format right. It is reasonably
1391self-explanatory once you're in there. This can be useful in order to
1392create a second file, say "~/.my_viminfo" which could contain certain
1393settings that you always want when you first start Vim. For example, you
1394can preload registers with particular data, or put certain commands in the
1395command line history. A line in your .vimrc file like >
1396 :rviminfo! ~/.my_viminfo
1397can be used to load this information. You could even have different viminfos
1398for different types of files (e.g., C code) and load them based on the file
1399name, using the ":autocmd" command (see |:autocmd|).
1400
1401 *viminfo-errors*
1402When Vim detects an error while reading a viminfo file, it will not overwrite
1403that file. If there are more than 10 errors, Vim stops reading the viminfo
1404file. This was done to avoid accidentally destroying a file when the file
1405name of the viminfo file is wrong. This could happen when accidentally typing
1406"vim -i file" when you wanted "vim -R file" (yes, somebody accidentally did
1407that!). If you want to overwrite a viminfo file with an error in it, you will
1408either have to fix the error, or delete the file (while Vim is running, so
1409most of the information will be restored).
1410
1411 *:rv* *:rviminfo* *E195*
1412:rv[iminfo][!] [file] Read from viminfo file [file] (default: see above).
1413 If [!] is given, then any information that is
1414 already set (registers, marks, etc.) will be
1415 overwritten. {not in Vi}
1416
1417 *:wv* *:wviminfo* *E137* *E138* *E574*
1418:wv[iminfo][!] [file] Write to viminfo file [file] (default: see above).
1419 The information in the file is first read in to make
1420 a merge between old and new info. When [!] is used,
1421 the old information is not read first, only the
1422 internal info is written. If 'viminfo' is empty, marks
1423 for up to 100 files will be written.
1424 When you get error "E138: Can't write viminfo file"
1425 check that no old temp files were left behind (e.g.
1426 ~/.viminf*) and that you can write in the directory of
1427 the .viminfo file.
1428 {not in Vi}
1429
1430 vim:tw=78:ts=8:ft=help:norl: