blob: 6682ba6aa72e1ab6ac65f9dcc90ec22b88bc18ac [file] [log] [blame]
Bram Moolenaar20f90cf2011-05-19 12:22:51 +02001*intro.txt* For Vim version 7.3. Last change: 2011 May 15
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Introduction to Vim *ref* *reference*
8
91. Introduction |intro|
102. Vim on the internet |internet|
113. Credits |credits|
124. Notation |notation|
135. Modes, introduction |vim-modes-intro|
146. Switching from mode to mode |mode-switching|
157. The window contents |window-contents|
168. Definitions |definitions|
17
18==============================================================================
191. Introduction *intro*
20
21Vim stands for Vi IMproved. It used to be Vi IMitation, but there are so many
22improvements that a name change was appropriate. Vim is a text editor which
23includes almost all the commands from the Unix program "Vi" and a lot of new
24ones. It is very useful for editing programs and other plain text.
25 All commands are given with the keyboard. This has the advantage that you
26can keep your fingers on the keyboard and your eyes on the screen. For those
27who want it, there is mouse support and a GUI version with scrollbars and
28menus (see |gui.txt|).
29
30An overview of this manual can be found in the file "help.txt", |help.txt|.
31It can be accessed from within Vim with the <Help> or <F1> key and with the
32|:help| command (just type ":help", without the bars or quotes).
33 The 'helpfile' option can be set to the name of the help file, in case it
34is not located in the default place. You can jump to subjects like with tags:
35Use CTRL-] to jump to a subject under the cursor, use CTRL-T to jump back.
36
37Throughout this manual the differences between Vi and Vim are mentioned in
38curly braces, like this: {Vi does not have on-line help}. See |vi_diff.txt|
39for a summary of the differences between Vim and Vi.
40
41This manual refers to Vim on various machines. There may be small differences
42between different computers and terminals. Besides the remarks given in this
43document, there is a separate document for each supported system, see
44|sys-file-list|.
45
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010046 *pronounce*
47Vim is pronounced as one word, like Jim, not vi-ai-em. It's written with a
48capital, since it's a name, again like Jim.
49
Bram Moolenaar071d4272004-06-13 20:20:40 +000050This manual is a reference for all the Vim commands and options. This is not
51an introduction to the use of Vi or Vim, it gets a bit complicated here and
52there. For beginners, there is a hands-on |tutor|. To learn using Vim, read
53the user manual |usr_toc.txt|.
54
55 *book*
56There are many books on Vi that contain a section for beginners. There are
57two books I can recommend:
58
59 "Vim - Vi Improved" by Steve Oualline
60
61This is the very first book completely dedicated to Vim. It is very good for
62beginners. The most often used commands are explained with pictures and
63examples. The less often used commands are also explained, the more advanced
64features are summarized. There is a comprehensive index and a quick
65reference. Parts of this book have been included in the user manual
66|frombook|.
67Published by New Riders Publishing. ISBN: 0735710015
68For more information try one of these:
69 http://iccf-holland.org/click5.html
70 http://www.vim.org/iccf/click5.html
71
72 "Learning the Vi editor" by Linda Lamb and Arnold Robbins
73
74This is a book about Vi that includes a chapter on Vim (in the sixth edition).
75The first steps in Vi are explained very well. The commands that Vim adds are
76only briefly mentioned. There is also a German translation.
77Published by O'Reilly. ISBN: 1-56592-426-6.
78
79==============================================================================
802. Vim on the internet *internet*
81
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000082 *www* *WWW* *faq* *FAQ* *distribution* *download*
Bram Moolenaar071d4272004-06-13 20:20:40 +000083The Vim pages contain the most recent information about Vim. They also
84contain links to the most recent version of Vim. The FAQ is a list of
85Frequently Asked Questions. Read this if you have problems.
86
87 VIM home page: http://www.vim.org/
88 VIM FAQ: http://vimdoc.sf.net/
89 Downloading: ftp://ftp.vim.org/pub/vim/MIRRORS
90
91
92Usenet News group where Vim is discussed: *news* *usenet*
93 comp.editors
94This group is also for other editors. If you write about Vim, don't forget to
95mention that.
96
97 *mail-list* *maillist*
98There are several mailing lists for Vim:
99<vim@vim.org>
100 For discussions about using existing versions of Vim: Useful mappings,
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000101 questions, answers, where to get a specific version, etc. There are
102 quite a few people watching this list and answering questions, also
103 for beginners. Don't hesitate to ask your question here.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104<vim-dev@vim.org> *vim-dev* *vimdev*
105 For discussions about changing Vim: New features, porting, patches,
106 beta-test versions, etc.
107<vim-announce@vim.org> *vim-announce*
108 Announcements about new versions of Vim; also for beta-test versions
Bram Moolenaarc6fe9192006-04-09 21:54:49 +0000109 and ports to different systems. This is a read-only list.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110<vim-multibyte@vim.org> *vim-multibyte*
111 For discussions about using and improving the multi-byte aspects of
112 Vim.
113<vim-mac@vim.org> *vim-mac*
114 For discussions about using and improving the Macintosh version of
115 Vim.
116
117See http://www.vim.org/maillist.php for the latest information.
118
119NOTE:
120- You can only send messages to these lists if you have subscribed!
121- You need to send the messages from the same location as where you subscribed
122 from (to avoid spam mail).
123- Maximum message size is 40000 characters.
124
125 *subscribe-maillist*
126If you want to join, send a message to
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000127 <vim-subscribe@vim.org>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128Make sure that your "From:" address is correct. Then the list server will
129give you help on how to subscribe.
130
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000131 *maillist-archive*
132For more information and archives look on the Vim maillist page:
133http://www.vim.org/maillist.php
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134
135
136Bug reports: *bugs* *bug-reports* *bugreport.vim*
137
Bram Moolenaar20f90cf2011-05-19 12:22:51 +0200138Send bug reports to: Vim Developers <vim_dev@vim.org>
139This is a maillist, many people will see the message. If you don't want that,
140e.g. because it is a security issue, send it to <bugs@vim.org>, this only goes
141to the Vim maintainer (that's Bram).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142Please be brief; all the time that is spent on answering mail is subtracted
143from the time that is spent on improving Vim! Always give a reproducible
144example and try to find out which settings or other things influence the
145appearance of the bug. Try different machines, if possible. Send me patches
146if you can!
147
Bram Moolenaare344bea2005-09-01 20:46:49 +0000148It will help to include information about the version of Vim you are using and
149your setup. You can get the information with this command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150 :so $VIMRUNTIME/bugreport.vim
151This will create a file "bugreport.txt" in the current directory, with a lot
152of information of your environment. Before sending this out, check if it
153doesn't contain any confidential information!
154
Bram Moolenaare344bea2005-09-01 20:46:49 +0000155If Vim crashes, please try to find out where. You can find help on this here:
156|debug.txt|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157
Bram Moolenaare344bea2005-09-01 20:46:49 +0000158In case of doubt or when you wonder if the problem has already been fixed but
159you can't find a fix for it, become a member of the vim-dev maillist and ask
160your question there. |maillist|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161
162 *year-2000* *Y2K*
163Since Vim internally doesn't use dates for editing, there is no year 2000
164problem to worry about. Vim does use the time in the form of seconds since
165January 1st 1970. It is used for a time-stamp check of the edited file and
166the swap file, which is not critical and should only cause warning messages.
167
168There might be a year 2038 problem, when the seconds don't fit in a 32 bit int
169anymore. This depends on the compiler, libraries and operating system.
170Specifically, time_t and the ctime() function are used. And the time_t is
171stored in four bytes in the swap file. But that's only used for printing a
172file date/time for recovery, it will never affect normal editing.
173
174The Vim strftime() function directly uses the strftime() system function.
175localtime() uses the time() system function. getftime() uses the time
176returned by the stat() system function. If your system libraries are year
1772000 compliant, Vim is too.
178
179The user may create scripts for Vim that use external commands. These might
180introduce Y2K problems, but those are not really part of Vim itself.
181
182==============================================================================
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00001833. Credits *credits* *author* *Bram* *Moolenaar*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184
185Most of Vim was written by Bram Moolenaar <Bram@vim.org>.
186
187Parts of the documentation come from several Vi manuals, written by:
188 W.N. Joy
189 Alan P.W. Hewett
190 Mark Horton
191
192The Vim editor is based on Stevie and includes (ideas from) other software,
193worked on by the people mentioned here. Other people helped by sending me
194patches, suggestions and giving feedback about what is good and bad in Vim.
195
196Vim would never have become what it is now, without the help of these people!
197
198 Ron Aaron Win32 GUI changes
Bram Moolenaar91604412010-06-03 20:25:18 +0200199 Mohsin Ahmed encryption
Bram Moolenaar071d4272004-06-13 20:20:40 +0000200 Zoltan Arpadffy work on VMS port
201 Tony Andrews Stevie
202 Gert van Antwerpen changes for DJGPP on MS-DOS
203 Berkeley DB(3) ideas for swap file implementation
204 Keith Bostic Nvi
205 Walter Briscoe Makefile updates, various patches
206 Ralf Brown SPAWNO library for MS-DOS
207 Robert Colon many useful remarks
208 Marcin Dalecki GTK+ GUI port, toolbar icons, gettext()
209 Kayhan Demirel sent me news in Uganda
210 Chris & John Downey xvi (ideas for multi-windows version)
211 Henk Elbers first VMS port
Bram Moolenaar7b0294c2004-10-11 10:16:09 +0000212 Daniel Elstner GTK+ 2 port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213 Eric Fischer Mac port, 'cindent', and other improvements
214 Benji Fisher Answering lots of user questions
215 Bill Foster Athena GUI port
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000216 Google Lets me work on Vim one day a week
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217 Loic Grenie xvim (ideas for multi windows version)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000218 Sven Guckes Vim promoter and previous WWW page maintainer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219 Darren Hiebert Exuberant ctags
Bram Moolenaar7b0294c2004-10-11 10:16:09 +0000220 Jason Hildebrand GTK+ 2 port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000221 Bruce Hunsaker improvements for VMS port
222 Andy Kahn Cscope support, GTK+ GUI port
223 Oezguer Kesim Maintainer of Vim Mailing Lists
224 Axel Kielhorn work on the Macintosh port
225 Steve Kirkendall Elvis
226 Roger Knobbe original port to Windows NT
227 Sergey Laskavy Vim's help from Moscow
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000228 Felix von Leitner Previous maintainer of Vim Mailing Lists
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229 David Leonard Port of Python extensions to Unix
230 Avner Lottem Edit in right-to-left windows
231 Flemming Madsen X11 client-server, various features and patches
Bram Moolenaar91604412010-06-03 20:25:18 +0200232 Tony Mechelynck answers many user questions
Bram Moolenaar071d4272004-06-13 20:20:40 +0000233 Paul Moore Python interface extensions, many patches
234 Katsuhito Nagano Work on multi-byte versions
235 Sung-Hyun Nam Work on multi-byte versions
236 Vince Negri Win32 GUI and generic console enhancements
237 Steve Oualline Author of the first Vim book |frombook|
Bram Moolenaar91604412010-06-03 20:25:18 +0200238 Dominique Pelle valgrind reports and many fixes
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000239 A.Politz Many bug reports and some fixes
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240 George V. Reilly Win32 port, Win32 GUI start-off
241 Stephen Riehm bug collector
242 Stefan Roemer various patches and help to users
243 Ralf Schandl IBM OS/390 port
244 Olaf Seibert DICE and BeBox version, regexp improvements
245 Mortaza Shiran Farsi patches
246 Peter da Silva termlib
247 Paul Slootman OS/2 port
248 Henry Spencer regular expressions
249 Dany St-Amant Macintosh port
250 Tim Thompson Stevie
251 G. R. (Fred) Walter Stevie
252 Sven Verdoolaege Perl interface
253 Robert Webb Command-line completion, GUI versions, and
254 lots of patches
255 Ingo Wilken Tcl interface
256 Mike Williams PostScript printing
257 Juergen Weigert Lattice version, AUX improvements, UNIX and
258 MS-DOS ports, autoconf
259 Stefan 'Sec' Zehl Maintainer of vim.org
260
261I wish to thank all the people that sent me bug reports and suggestions. The
262list is too long to mention them all here. Vim would not be the same without
263the ideas from all these people: They keep Vim alive!
264
265
266In this documentation there are several references to other versions of Vi:
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000267 *Vi* *vi*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268Vi "the original". Without further remarks this is the version
269 of Vi that appeared in Sun OS 4.x. ":version" returns
270 "Version 3.7, 6/7/85". Sometimes other versions are referred
271 to. Only runs under Unix. Source code only available with a
272 license. More information on Vi can be found through:
273 http://vi-editor.org [doesn't currently work...]
274 *Posix*
275Posix From the IEEE standard 1003.2, Part 2: Shell and utilities.
276 Generally known as "Posix". This is a textual description of
277 how Vi is supposed to work.
Bram Moolenaar7c626922005-02-07 22:01:03 +0000278 See |posix-compliance|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279 *Nvi*
280Nvi The "New" Vi. The version of Vi that comes with BSD 4.4 and FreeBSD.
281 Very good compatibility with the original Vi, with a few extensions.
282 The version used is 1.79. ":version" returns "Version 1.79
283 (10/23/96)". There has been no release the last few years, although
284 there is a development version 1.81.
285 Source code is freely available.
286 *Elvis*
287Elvis Another Vi clone, made by Steve Kirkendall. Very compact but isn't
288 as flexible as Vim.
289 The version used is 2.1. It is still being developed. Source code is
290 freely available.
291
292==============================================================================
2934. Notation *notation*
294
295When syntax highlighting is used to read this, text that is not typed
296literally is often highlighted with the Special group. These are items in [],
297{} and <>, and CTRL-X.
298
299Note that Vim uses all possible characters in commands. Sometimes the [], {}
300and <> are part of what you type, the context should make this clear.
301
302
303[] Characters in square brackets are optional.
304
Bram Moolenaar4a748032010-09-30 21:47:56 +0200305 *count* *[count]*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306[count] An optional number that may precede the command to multiply
307 or iterate the command. If no number is given, a count of one
308 is used, unless otherwise noted. Note that in this manual the
309 [count] is not mentioned in the description of the command,
310 but only in the explanation. This was done to make the
311 commands easier to look up. If the 'showcmd' option is on,
312 the (partially) entered count is shown at the bottom of the
313 window. You can use <Del> to erase the last digit (|N<Del>|).
314
315 *[quotex]*
316["x] An optional register designation where text can be stored.
317 See |registers|. The x is a single character between 'a' and
318 'z' or 'A' and 'Z' or '"', and in some cases (with the put
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000319 command) between '0' and '9', '%', '#', or others. The
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320 uppercase and lowercase letter designate the same register,
321 but the lowercase letter is used to overwrite the previous
322 register contents, while the uppercase letter is used to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000323 append to the previous register contents. Without the ""x" or
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324 with """" the stored text is put into the unnamed register.
325
326 *{}*
327{} Curly braces denote parts of the command which must appear,
328 but which can take a number of different values. The
329 differences between Vim and Vi are also given in curly braces
330 (this will be clear from the context).
331
332 *{char1-char2}*
333{char1-char2} A single character from the range char1 to char2. For
334 example: {a-z} is a lowercase letter. Multiple ranges may be
335 concatenated. For example, {a-zA-Z0-9} is any alphanumeric
336 character.
337
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000338 *{motion}* *movement*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339{motion} A command that moves the cursor. These are explained in
340 |motion.txt|. Examples:
341 w to start of next word
342 b to begin of current word
343 4j four lines down
344 /The<CR> to next occurrence of "The"
345 This is used after an |operator| command to move over the text
346 that is to be operated upon.
347 - If the motion includes a count and the operator also has a
348 count, the two counts are multiplied. For example: "2d3w"
349 deletes six words.
350 - The motion can be backwards, e.g. "db" to delete to the
351 start of the word.
352 - The motion can also be a mouse click. The mouse is not
353 supported in every terminal though.
354 - The ":omap" command can be used to map characters while an
355 operator is pending.
356 - Ex commands can be used to move the cursor. This can be
357 used to call a function that does some complicated motion.
358 The motion is always characterwise exclusive, no matter
359 what ":" command is used. This means it's impossible to
360 include the last character of a line without the line break
361 (unless 'virtualedit' is set).
362 If the Ex command changes the text before where the operator
363 starts or jumps to another buffer the result is
364 unpredictable. It is possible to change the text further
365 down. Jumping to another buffer is possible if the current
366 buffer is not unloaded.
367
368 *{Visual}*
369{Visual} A selected text area. It is started with the "v", "V", or
370 CTRL-V command, then any cursor movement command can be used
371 to change the end of the selected text.
372 This is used before an |operator| command to highlight the
373 text that is to be operated upon.
374 See |Visual-mode|.
375
376 *<character>*
377<character> A special character from the table below, optionally with
378 modifiers, or a single ASCII character with modifiers.
379
380 *'character'*
381'c' A single ASCII character.
382
383 *CTRL-{char}*
384CTRL-{char} {char} typed as a control character; that is, typing {char}
385 while holding the CTRL key down. The case of {char} does not
386 matter; thus CTRL-A and CTRL-a are equivalent. But on some
387 terminals, using the SHIFT key will produce another code,
388 don't use it then.
389
390 *'option'*
391'option' An option, or parameter, that can be set to a value, is
392 enclosed in single quotes. See |options|.
393
394 *quotecommandquote*
395"command" A reference to a command that you can type is enclosed in
396 double quotes.
397
398 *key-notation* *key-codes* *keycodes*
399These names for keys are used in the documentation. They can also be used
400with the ":map" command (insert the key name by pressing CTRL-K and then the
401key you want the name for).
402
403notation meaning equivalent decimal value(s) ~
404-----------------------------------------------------------------------
405<Nul> zero CTRL-@ 0 (stored as 10) *<Nul>*
406<BS> backspace CTRL-H 8 *backspace*
407<Tab> tab CTRL-I 9 *tab* *Tab*
408 *linefeed*
409<NL> linefeed CTRL-J 10 (used for <Nul>)
410<FF> formfeed CTRL-L 12 *formfeed*
411<CR> carriage return CTRL-M 13 *carriage-return*
412<Return> same as <CR> *<Return>*
413<Enter> same as <CR> *<Enter>*
414<Esc> escape CTRL-[ 27 *escape* *<Esc>*
415<Space> space 32 *space*
416<lt> less-than < 60 *<lt>*
417<Bslash> backslash \ 92 *backslash* *<Bslash>*
418<Bar> vertical bar | 124 *<Bar>*
419<Del> delete 127
420<CSI> command sequence intro ALT-Esc 155 *<CSI>*
421<xCSI> CSI when typed in the GUI *<xCSI>*
422
423<EOL> end-of-line (can be <CR>, <LF> or <CR><LF>,
424 depends on system and 'fileformat') *<EOL>*
425
426<Up> cursor-up *cursor-up* *cursor_up*
427<Down> cursor-down *cursor-down* *cursor_down*
428<Left> cursor-left *cursor-left* *cursor_left*
429<Right> cursor-right *cursor-right* *cursor_right*
430<S-Up> shift-cursor-up
431<S-Down> shift-cursor-down
432<S-Left> shift-cursor-left
433<S-Right> shift-cursor-right
434<C-Left> control-cursor-left
435<C-Right> control-cursor-right
436<F1> - <F12> function keys 1 to 12 *function_key* *function-key*
437<S-F1> - <S-F12> shift-function keys 1 to 12 *<S-F1>*
438<Help> help key
439<Undo> undo key
440<Insert> insert key
441<Home> home *home*
442<End> end *end*
443<PageUp> page-up *page_up* *page-up*
444<PageDown> page-down *page_down* *page-down*
445<kHome> keypad home (upper left) *keypad-home*
446<kEnd> keypad end (lower left) *keypad-end*
447<kPageUp> keypad page-up (upper right) *keypad-page-up*
448<kPageDown> keypad page-down (lower right) *keypad-page-down*
449<kPlus> keypad + *keypad-plus*
450<kMinus> keypad - *keypad-minus*
451<kMultiply> keypad * *keypad-multiply*
452<kDivide> keypad / *keypad-divide*
453<kEnter> keypad Enter *keypad-enter*
454<kPoint> keypad Decimal point *keypad-point*
455<k0> - <k9> keypad 0 to 9 *keypad-0* *keypad-9*
456<S-...> shift-key *shift* *<S-*
457<C-...> control-key *control* *ctrl* *<C-*
458<M-...> alt-key or meta-key *meta* *alt* *<M-*
459<A-...> same as <M-...> *<A-*
460<D-...> command-key (Macintosh only) *<D-*
461<t_xx> key with "xx" entry in termcap
462-----------------------------------------------------------------------
463
464Note: The shifted cursor keys, the help key, and the undo key are only
465available on a few terminals. On the Amiga, shifted function key 10 produces
466a code (CSI) that is also used by key sequences. It will be recognized only
467after typing another key.
468
469Note: There are two codes for the delete key. 127 is the decimal ASCII value
470for the delete key, which is always recognized. Some delete keys send another
471value, in which case this value is obtained from the termcap entry "kD". Both
472values have the same effect. Also see |:fixdel|.
473
474Note: The keypad keys are used in the same way as the corresponding "normal"
475keys. For example, <kHome> has the same effect as <Home>. If a keypad key
476sends the same raw key code as its non-keypad equivalent, it will be
477recognized as the non-keypad code. For example, when <kHome> sends the same
478code as <Home>, when pressing <kHome> Vim will think <Home> was pressed.
479Mapping <kHome> will not work then.
480
481 *<>*
482Examples are often given in the <> notation. Sometimes this is just to make
483clear what you need to type, but often it can be typed literally, e.g., with
484the ":map" command. The rules are:
485 1. Any printable characters are typed directly, except backslash and '<'
486 2. A backslash is represented with "\\", double backslash, or "<Bslash>".
487 3. A real '<' is represented with "\<" or "<lt>". When there is no
488 confusion possible, a '<' can be used directly.
489 4. "<key>" means the special key typed. This is the notation explained in
490 the table above. A few examples:
491 <Esc> Escape key
492 <C-G> CTRL-G
493 <Up> cursor up key
494 <C-LeftMouse> Control- left mouse click
495 <S-F11> Shifted function key 11
496 <M-a> Meta- a ('a' with bit 8 set)
497 <M-A> Meta- A ('A' with bit 8 set)
498 <t_kd> "kd" termcap entry (cursor down key)
499
500If you want to use the full <> notation in Vim, you have to make sure the '<'
501flag is excluded from 'cpoptions' (when 'compatible' is not set, it already is
502by default). >
503 :set cpo-=<
504The <> notation uses <lt> to escape the special meaning of key names. Using a
505backslash also works, but only when 'cpoptions' does not include the 'B' flag.
506
507Examples for mapping CTRL-H to the six characters "<Home>": >
508 :imap <C-H> \<Home>
509 :imap <C-H> <lt>Home>
510The first one only works when the 'B' flag is not in 'cpoptions'. The second
511one always works.
512To get a literal "<lt>" in a mapping: >
513 :map <C-L> <lt>lt>
514
515For mapping, abbreviation and menu commands you can then copy-paste the
516examples and use them directly. Or type them literally, including the '<' and
517'>' characters. This does NOT work for other commands, like ":set" and
518":autocmd"!
519
520==============================================================================
5215. Modes, introduction *vim-modes-intro* *vim-modes*
522
523Vim has six BASIC modes:
524
525 *Normal* *Normal-mode* *command-mode*
526Normal mode In Normal mode you can enter all the normal editor
527 commands. If you start the editor you are in this
528 mode (unless you have set the 'insertmode' option,
529 see below). This is also known as command mode.
530
531Visual mode This is like Normal mode, but the movement commands
532 extend a highlighted area. When a non-movement
533 command is used, it is executed for the highlighted
534 area. See |Visual-mode|.
535 If the 'showmode' option is on "-- VISUAL --" is shown
536 at the bottom of the window.
537
538Select mode This looks most like the MS-Windows selection mode.
539 Typing a printable character deletes the selection
540 and starts Insert mode. See |Select-mode|.
541 If the 'showmode' option is on "-- SELECT --" is shown
542 at the bottom of the window.
543
544Insert mode In Insert mode the text you type is inserted into the
545 buffer. See |Insert-mode|.
546 If the 'showmode' option is on "-- INSERT --" is shown
547 at the bottom of the window.
548
549Command-line mode In Command-line mode (also called Cmdline mode) you
550Cmdline mode can enter one line of text at the bottom of the
551 window. This is for the Ex commands, ":", the pattern
552 search commands, "?" and "/", and the filter command,
553 "!". |Cmdline-mode|
554
555Ex mode Like Command-line mode, but after entering a command
556 you remain in Ex mode. Very limited editing of the
557 command line. |Ex-mode|
558
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000559There are six ADDITIONAL modes. These are variants of the BASIC modes:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560
561 *Operator-pending* *Operator-pending-mode*
562Operator-pending mode This is like Normal mode, but after an operator
563 command has started, and Vim is waiting for a {motion}
564 to specify the text that the operator will work on.
565
566Replace mode Replace mode is a special case of Insert mode. You
567 can do the same things as in Insert mode, but for
568 each character you enter, one character of the existing
569 text is deleted. See |Replace-mode|.
570 If the 'showmode' option is on "-- REPLACE --" is
571 shown at the bottom of the window.
572
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000573Virtual Replace mode Virtual Replace mode is similar to Replace mode, but
574 instead of file characters you are replacing screen
575 real estate. See |Virtual-Replace-mode|.
576 If the 'showmode' option is on "-- VREPLACE --" is
577 shown at the bottom of the window.
578
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579Insert Normal mode Entered when CTRL-O given in Insert mode. This is
580 like Normal mode, but after executing one command Vim
581 returns to Insert mode.
582 If the 'showmode' option is on "-- (insert) --" is
583 shown at the bottom of the window.
584
585Insert Visual mode Entered when starting a Visual selection from Insert
586 mode, e.g., by using CTRL-O and then "v", "V" or
587 CTRL-V. When the Visual selection ends, Vim returns
588 to Insert mode.
589 If the 'showmode' option is on "-- (insert) VISUAL --"
590 is shown at the bottom of the window.
591
592Insert Select mode Entered when starting Select mode from Insert mode.
593 E.g., by dragging the mouse or <S-Right>.
594 When the Select mode ends, Vim returns to Insert mode.
595 If the 'showmode' option is on "-- (insert) SELECT --"
596 is shown at the bottom of the window.
597
598==============================================================================
5996. Switching from mode to mode *mode-switching*
600
601If for any reason you do not know which mode you are in, you can always get
602back to Normal mode by typing <Esc> twice. This doesn't work for Ex mode
603though, use ":visual".
604You will know you are back in Normal mode when you see the screen flash or
605hear the bell after you type <Esc>. However, when pressing <Esc> after using
606CTRL-O in Insert mode you get a beep but you are still in Insert mode, type
607<Esc> again.
608
609 *i_esc*
610 TO mode ~
611 Normal Visual Select Insert Replace Cmd-line Ex ~
612FROM mode ~
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000613Normal v V ^V *4 *1 R gR : / ? ! Q
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614Visual *2 ^G c C -- : --
615Select *5 ^O ^G *6 -- -- --
616Insert <Esc> -- -- <Insert> -- --
617Replace <Esc> -- -- <Insert> -- --
618Command-line *3 -- -- :start -- --
619Ex :vi -- -- -- -- --
620
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621-- not possible
622
623*1 Go from Normal mode to Insert mode by giving the command "i", "I", "a",
624 "A", "o", "O", "c", "C", "s" or S".
625*2 Go from Visual mode to Normal mode by giving a non-movement command, which
626 causes the command to be executed, or by hitting <Esc> "v", "V" or "CTRL-V"
627 (see |v_v|), which just stops Visual mode without side effects.
628*3 Go from Command-line mode to Normal mode by:
629 - Hitting <CR> or <NL>, which causes the entered command to be executed.
630 - Deleting the complete line (e.g., with CTRL-U) and giving a final <BS>.
631 - Hitting CTRL-C or <Esc>, which quits the command-line without executing
632 the command.
633 In the last case <Esc> may be the character defined with the 'wildchar'
634 option, in which case it will start command-line completion. You can
635 ignore that and type <Esc> again. {Vi: when hitting <Esc> the command-line
636 is executed. This is unexpected for most people; therefore it was changed
637 in Vim. But when the <Esc> is part of a mapping, the command-line is
638 executed. If you want the Vi behaviour also when typing <Esc>, use ":cmap
639 ^V<Esc> ^V^M"}
640*4 Go from Normal to Select mode by:
641 - use the mouse to select text while 'selectmode' contains "mouse"
642 - use a non-printable command to move the cursor while keeping the Shift
643 key pressed, and the 'selectmode' option contains "key"
644 - use "v", "V" or "CTRL-V" while 'selectmode' contains "cmd"
645 - use "gh", "gH" or "g CTRL-H" |g_CTRL-H|
646*5 Go from Select mode to Normal mode by using a non-printable command to move
647 the cursor, without keeping the Shift key pressed.
648*6 Go from Select mode to Insert mode by typing a printable character. The
649 selection is deleted and the character is inserted.
650
651If the 'insertmode' option is on, editing a file will start in Insert mode.
652
653 *CTRL-\_CTRL-N* *i_CTRL-\_CTRL-N* *c_CTRL-\_CTRL-N* *v_CTRL-\_CTRL-N*
654Additionally the command CTRL-\ CTRL-N or <C-\><C-N> can be used to go to
655Normal mode from any other mode. This can be used to make sure Vim is in
656Normal mode, without causing a beep like <Esc> would. However, this does not
657work in Ex mode. When used after a command that takes an argument, such as
658|f| or |m|, the timeout set with 'ttimeoutlen' applies.
659
660 *CTRL-\_CTRL-G* *i_CTRL-\_CTRL-G* *c_CTRL-\_CTRL-G* *v_CTRL-\_CTRL-G*
661The command CTRL-\ CTRL-G or <C-\><C-G> can be used to go to Insert mode when
662'insertmode' is set. Otherwise it goes to Normal mode. This can be used to
663make sure Vim is in the mode indicated by 'insertmode', without knowing in
664what mode Vim currently is.
665
666 *Q* *mode-Ex* *Ex-mode* *Ex* *EX* *E501*
667Q Switch to "Ex" mode. This is a bit like typing ":"
668 commands one after another, except:
669 - You don't have to keep pressing ":".
670 - The screen doesn't get updated after each command.
671 - There is no normal command-line editing.
672 - Mappings and abbreviations are not used.
673 In fact, you are editing the lines with the "standard"
674 line-input editing commands (<Del> or <BS> to erase,
675 CTRL-U to kill the whole line).
676 Vim will enter this mode by default if it's invoked as
677 "ex" on the command-line.
678 Use the ":vi" command |:visual| to exit "Ex" mode.
679 Note: In older versions of Vim "Q" formatted text,
680 that is now done with |gq|. But if you use the
681 |vimrc_example.vim| script "Q" works like "gq".
682
683 *gQ*
Bram Moolenaar7c626922005-02-07 22:01:03 +0000684gQ Switch to "Ex" mode like with "Q", but really behave
685 like typing ":" commands after another. All command
686 line editing, completion etc. is available.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000687 Use the ":vi" command |:visual| to exit "Ex" mode.
688 {not in Vi}
689
690==============================================================================
6917. The window contents *window-contents*
692
693In Normal mode and Insert/Replace mode the screen window will show the current
694contents of the buffer: What You See Is What You Get. There are two
695exceptions:
696- When the 'cpoptions' option contains '$', and the change is within one line,
697 the text is not directly deleted, but a '$' is put at the last deleted
698 character.
699- When inserting text in one window, other windows on the same text are not
700 updated until the insert is finished.
701{Vi: The screen is not always updated on slow terminals}
702
703Lines longer than the window width will wrap, unless the 'wrap' option is off
704(see below). The 'linebreak' option can be set to wrap at a blank character.
705
706If the window has room after the last line of the buffer, Vim will show '~' in
Bram Moolenaar166af9b2010-11-16 20:34:40 +0100707the first column of the last lines in the window, like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708
709 +-----------------------+
710 |some line |
711 |last line |
712 |~ |
713 |~ |
714 +-----------------------+
715
716Thus the '~' lines indicate that the end of the buffer was reached.
717
718If the last line in a window doesn't fit, Vim will indicate this with a '@' in
Bram Moolenaar166af9b2010-11-16 20:34:40 +0100719the first column of the last lines in the window, like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720
721 +-----------------------+
722 |first line |
723 |second line |
724 |@ |
725 |@ |
726 +-----------------------+
727
728Thus the '@' lines indicate that there is a line that doesn't fit in the
729window.
730
731When the "lastline" flag is present in the 'display' option, you will not see
732'@' characters at the left side of window. If the last line doesn't fit
733completely, only the part that fits is shown, and the last three characters of
Bram Moolenaar81af9252010-12-10 20:35:50 +0100734the last line are replaced with "@@@", like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000735
736 +-----------------------+
737 |first line |
738 |second line |
739 |a very long line that d|
740 |oesn't fit in the wi@@@|
741 +-----------------------+
742
743If there is a single line that is too long to fit in the window, this is a
744special situation. Vim will show only part of the line, around where the
745cursor is. There are no special characters shown, so that you can edit all
746parts of this line.
747{Vi: gives an "internal error" on lines that do not fit in the window}
748
749The '@' occasion in the 'highlight' option can be used to set special
750highlighting for the '@' and '~' characters. This makes it possible to
751distinguish them from real characters in the buffer.
752
753The 'showbreak' option contains the string to put in front of wrapped lines.
754
755 *wrap-off*
756If the 'wrap' option is off, long lines will not wrap. Only the part that
757fits on the screen is shown. If the cursor is moved to a part of the line
758that is not shown, the screen is scrolled horizontally. The advantage of
759this method is that columns are shown as they are and lines that cannot fit
760on the screen can be edited. The disadvantage is that you cannot see all the
761characters of a line at once. The 'sidescroll' option can be set to the
762minimal number of columns to scroll. {Vi: has no 'wrap' option}
763
764All normal ASCII characters are displayed directly on the screen. The <Tab>
765is replaced with the number of spaces that it represents. Other non-printing
766characters are replaced with "^{char}", where {char} is the non-printing
767character with 64 added. Thus character 7 (bell) will be shown as "^G".
768Characters between 127 and 160 are replaced with "~{char}", where {char} is
769the character with 64 subtracted. These characters occupy more than one
770position on the screen. The cursor can only be positioned on the first one.
771
772If you set the 'number' option, all lines will be preceded with their
773number. Tip: If you don't like wrapping lines to mix with the line numbers,
774set the 'showbreak' option to eight spaces:
775 ":set showbreak=\ \ \ \ \ \ \ \ "
776
777If you set the 'list' option, <Tab> characters will not be shown as several
778spaces, but as "^I". A '$' will be placed at the end of the line, so you can
779find trailing blanks.
780
781In Command-line mode only the command-line itself is shown correctly. The
782display of the buffer contents is updated as soon as you go back to Command
783mode.
784
785The last line of the window is used for status and other messages. The
786status messages will only be used if an option is on:
787
788status message option default Unix default ~
789current mode 'showmode' on on
790command characters 'showcmd' on off
791cursor position 'ruler' off off
792
793The current mode is "-- INSERT --" or "-- REPLACE --", see |'showmode'|. The
794command characters are those that you typed but were not used yet. {Vi: does
795not show the characters you typed or the cursor position}
796
797If you have a slow terminal you can switch off the status messages to speed
798up editing:
799 :set nosc noru nosm
800
801If there is an error, an error message will be shown for at least one second
802(in reverse video). {Vi: error messages may be overwritten with other
803messages before you have a chance to read them}
804
805Some commands show how many lines were affected. Above which threshold this
806happens can be controlled with the 'report' option (default 2).
807
808On the Amiga Vim will run in a CLI window. The name Vim and the full name of
809the current file name will be shown in the title bar. When the window is
810resized, Vim will automatically redraw the window. You may make the window as
811small as you like, but if it gets too small not a single line will fit in it.
812Make it at least 40 characters wide to be able to read most messages on the
813last line.
814
815On most Unix systems, resizing the window is recognized and handled correctly
816by Vim. {Vi: not ok}
817
818==============================================================================
8198. Definitions *definitions*
820
821 screen The whole area that Vim uses to work in. This can be
822 a terminal emulator window. Also called "the Vim
823 window".
824 window A view on a buffer.
825
826A screen contains one or more windows, separated by status lines and with the
827command line at the bottom.
828
829 +-------------------------------+
830screen | window 1 | window 2 |
831 | | |
832 | | |
833 |= status line =|= status line =|
834 | window 3 |
835 | |
836 | |
837 |==== status line ==============|
838 |command line |
839 +-------------------------------+
840
841The command line is also used for messages. It scrolls up the screen when
842there is not enough room in the command line.
843
844A difference is made between four types of lines:
845
846 buffer lines The lines in the buffer. This is the same as the
847 lines as they are read from/written to a file. They
848 can be thousands of characters long.
849 logical lines The buffer lines with folding applied. Buffer lines
850 in a closed fold are changed to a single logical line:
851 "+-- 99 lines folded". They can be thousands of
852 characters long.
853 window lines The lines displayed in a window: A range of logical
854 lines with wrapping, line breaks, etc. applied. They
855 can only be as long as the width of the window allows,
856 longer lines are wrapped or truncated.
857 screen lines The lines of the screen that Vim uses. Consists of
858 the window lines of all windows, with status lines
859 and the command line added. They can only be as long
860 as the width of the screen allows. When the command
861 line gets longer it wraps and lines are scrolled to
862 make room.
863
864buffer lines logical lines window lines screen lines ~
865
8661. one 1. one 1. +-- folded 1. +-- folded
8672. two 2. +-- folded 2. five 2. five
8683. three 3. five 3. six 3. six
8694. four 4. six 4. seven 4. seven
8705. five 5. seven 5. === status line ===
8716. six 6. aaa
8727. seven 7. bbb
873 8. ccc ccc c
8741. aaa 1. aaa 1. aaa 9. cc
8752. bbb 2. bbb 2. bbb 10. ddd
8763. ccc ccc ccc 3. ccc ccc ccc 3. ccc ccc c 11. ~
8774. ddd 4. ddd 4. cc 12. === status line ===
878 5. ddd 13. (command line)
879 6. ~
880
881==============================================================================
882 vim:tw=78:ts=8:ft=help:norl: