blob: 13542de23b4f6be6d9b2c36d79702b42d6a91edf [file] [log] [blame]
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001*intro.txt* For Vim version 8.1. Last change: 2018 Jan 24
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
Bram Moolenaar6aa8cea2017-06-05 14:44:35 +020087 Vim home page: http://www.vim.org/
88 Vim FAQ: http://vimdoc.sf.net/
Bram Moolenaar071d4272004-06-13 20:20:40 +000089 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:
Bram Moolenaar68563932017-01-10 13:31:15 +010099<vim@vim.org> *vim-use* *vim_use*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100 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 Moolenaar68563932017-01-10 13:31:15 +0100104<vim-dev@vim.org> *vim-dev* *vim_dev* *vimdev*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000105 For discussions about changing Vim: New features, porting, patches,
106 beta-test versions, etc.
Bram Moolenaar68563932017-01-10 13:31:15 +0100107<vim-announce@vim.org> *vim-announce* *vim_announce*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108 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 Moolenaar68563932017-01-10 13:31:15 +0100110<vim-mac@vim.org> *vim-mac* *vim_mac*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111 For discussions about using and improving the Macintosh version of
112 Vim.
113
114See http://www.vim.org/maillist.php for the latest information.
115
116NOTE:
117- You can only send messages to these lists if you have subscribed!
118- You need to send the messages from the same location as where you subscribed
119 from (to avoid spam mail).
120- Maximum message size is 40000 characters.
121
122 *subscribe-maillist*
123If you want to join, send a message to
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000124 <vim-subscribe@vim.org>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125Make sure that your "From:" address is correct. Then the list server will
126give you help on how to subscribe.
127
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000128 *maillist-archive*
129For more information and archives look on the Vim maillist page:
130http://www.vim.org/maillist.php
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131
132
133Bug reports: *bugs* *bug-reports* *bugreport.vim*
134
Bram Moolenaar3e496b02016-09-25 22:11:48 +0200135There are two ways to report bugs, both work:
1361. Send bug reports to: Vim Developers <vim-dev@vim.org>
137 This is a maillist, you need to become a member first and many people will
138 see the message. If you don't want that, e.g. because it is a security
139 issue, send it to <bugs@vim.org>, this only goes to the Vim maintainer
140 (that's Bram).
Bram Moolenaar40962ec2018-01-28 22:47:25 +01001412. Open an issue on GitHub: https://github.com/vim/vim/issues
Bram Moolenaar3e496b02016-09-25 22:11:48 +0200142 The text will be forwarded to the vim-dev maillist.
Bram Moolenaar822ff862014-06-12 21:46:14 +0200143
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144Please be brief; all the time that is spent on answering mail is subtracted
145from the time that is spent on improving Vim! Always give a reproducible
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200146example and try to find out which settings or other things trigger the bug.
147
148Preferably start Vim with: >
149 vim --clean -u reproduce.vim
150Where reproduce.vim is a script that reproduces the problem. Try different
151machines, if relevant (is this an MS-Windows specific bug perhaps?).
152
153Send me patches if you can!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000154
Bram Moolenaare344bea2005-09-01 20:46:49 +0000155It will help to include information about the version of Vim you are using and
156your setup. You can get the information with this command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157 :so $VIMRUNTIME/bugreport.vim
158This will create a file "bugreport.txt" in the current directory, with a lot
159of information of your environment. Before sending this out, check if it
160doesn't contain any confidential information!
161
Bram Moolenaare344bea2005-09-01 20:46:49 +0000162If Vim crashes, please try to find out where. You can find help on this here:
163|debug.txt|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164
Bram Moolenaare344bea2005-09-01 20:46:49 +0000165In case of doubt or when you wonder if the problem has already been fixed but
166you can't find a fix for it, become a member of the vim-dev maillist and ask
167your question there. |maillist|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168
169 *year-2000* *Y2K*
170Since Vim internally doesn't use dates for editing, there is no year 2000
171problem to worry about. Vim does use the time in the form of seconds since
172January 1st 1970. It is used for a time-stamp check of the edited file and
173the swap file, which is not critical and should only cause warning messages.
174
175There might be a year 2038 problem, when the seconds don't fit in a 32 bit int
176anymore. This depends on the compiler, libraries and operating system.
177Specifically, time_t and the ctime() function are used. And the time_t is
178stored in four bytes in the swap file. But that's only used for printing a
179file date/time for recovery, it will never affect normal editing.
180
181The Vim strftime() function directly uses the strftime() system function.
182localtime() uses the time() system function. getftime() uses the time
183returned by the stat() system function. If your system libraries are year
1842000 compliant, Vim is too.
185
186The user may create scripts for Vim that use external commands. These might
187introduce Y2K problems, but those are not really part of Vim itself.
188
189==============================================================================
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00001903. Credits *credits* *author* *Bram* *Moolenaar*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191
192Most of Vim was written by Bram Moolenaar <Bram@vim.org>.
193
194Parts of the documentation come from several Vi manuals, written by:
195 W.N. Joy
196 Alan P.W. Hewett
197 Mark Horton
198
199The Vim editor is based on Stevie and includes (ideas from) other software,
200worked on by the people mentioned here. Other people helped by sending me
201patches, suggestions and giving feedback about what is good and bad in Vim.
202
203Vim would never have become what it is now, without the help of these people!
204
205 Ron Aaron Win32 GUI changes
Bram Moolenaar91604412010-06-03 20:25:18 +0200206 Mohsin Ahmed encryption
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207 Zoltan Arpadffy work on VMS port
208 Tony Andrews Stevie
209 Gert van Antwerpen changes for DJGPP on MS-DOS
210 Berkeley DB(3) ideas for swap file implementation
211 Keith Bostic Nvi
212 Walter Briscoe Makefile updates, various patches
213 Ralf Brown SPAWNO library for MS-DOS
214 Robert Colon many useful remarks
215 Marcin Dalecki GTK+ GUI port, toolbar icons, gettext()
216 Kayhan Demirel sent me news in Uganda
217 Chris & John Downey xvi (ideas for multi-windows version)
218 Henk Elbers first VMS port
Bram Moolenaar7b0294c2004-10-11 10:16:09 +0000219 Daniel Elstner GTK+ 2 port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220 Eric Fischer Mac port, 'cindent', and other improvements
221 Benji Fisher Answering lots of user questions
222 Bill Foster Athena GUI port
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000223 Google Lets me work on Vim one day a week
Bram Moolenaar071d4272004-06-13 20:20:40 +0000224 Loic Grenie xvim (ideas for multi windows version)
Bram Moolenaarc236c162008-07-13 17:41:49 +0000225 Sven Guckes Vim promoter and previous WWW page maintainer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226 Darren Hiebert Exuberant ctags
Bram Moolenaar7b0294c2004-10-11 10:16:09 +0000227 Jason Hildebrand GTK+ 2 port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228 Bruce Hunsaker improvements for VMS port
229 Andy Kahn Cscope support, GTK+ GUI port
230 Oezguer Kesim Maintainer of Vim Mailing Lists
231 Axel Kielhorn work on the Macintosh port
232 Steve Kirkendall Elvis
233 Roger Knobbe original port to Windows NT
234 Sergey Laskavy Vim's help from Moscow
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000235 Felix von Leitner Previous maintainer of Vim Mailing Lists
Bram Moolenaar071d4272004-06-13 20:20:40 +0000236 David Leonard Port of Python extensions to Unix
237 Avner Lottem Edit in right-to-left windows
238 Flemming Madsen X11 client-server, various features and patches
Bram Moolenaar91604412010-06-03 20:25:18 +0200239 Tony Mechelynck answers many user questions
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240 Paul Moore Python interface extensions, many patches
241 Katsuhito Nagano Work on multi-byte versions
242 Sung-Hyun Nam Work on multi-byte versions
243 Vince Negri Win32 GUI and generic console enhancements
244 Steve Oualline Author of the first Vim book |frombook|
Bram Moolenaar91604412010-06-03 20:25:18 +0200245 Dominique Pelle valgrind reports and many fixes
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000246 A.Politz Many bug reports and some fixes
Bram Moolenaar071d4272004-06-13 20:20:40 +0000247 George V. Reilly Win32 port, Win32 GUI start-off
248 Stephen Riehm bug collector
249 Stefan Roemer various patches and help to users
250 Ralf Schandl IBM OS/390 port
251 Olaf Seibert DICE and BeBox version, regexp improvements
252 Mortaza Shiran Farsi patches
253 Peter da Silva termlib
254 Paul Slootman OS/2 port
255 Henry Spencer regular expressions
256 Dany St-Amant Macintosh port
257 Tim Thompson Stevie
258 G. R. (Fred) Walter Stevie
259 Sven Verdoolaege Perl interface
260 Robert Webb Command-line completion, GUI versions, and
261 lots of patches
262 Ingo Wilken Tcl interface
263 Mike Williams PostScript printing
264 Juergen Weigert Lattice version, AUX improvements, UNIX and
265 MS-DOS ports, autoconf
266 Stefan 'Sec' Zehl Maintainer of vim.org
Bram Moolenaar37c64c72017-09-19 22:06:03 +0200267 Yasuhiro Matsumoto many MS-Windows improvements
268 Ken Takata fixes and features
269 Kazunobu Kuriyama GTK 3
270 Christian Brabandt many fixes, features, user support, etc.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000271
272I wish to thank all the people that sent me bug reports and suggestions. The
273list is too long to mention them all here. Vim would not be the same without
274the ideas from all these people: They keep Vim alive!
Bram Moolenaar56b45b92013-06-24 22:22:18 +0200275*love* *peace* *friendship* *gross-national-happiness*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276
277
278In this documentation there are several references to other versions of Vi:
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000279 *Vi* *vi*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280Vi "the original". Without further remarks this is the version
281 of Vi that appeared in Sun OS 4.x. ":version" returns
282 "Version 3.7, 6/7/85". Sometimes other versions are referred
283 to. Only runs under Unix. Source code only available with a
284 license. More information on Vi can be found through:
285 http://vi-editor.org [doesn't currently work...]
286 *Posix*
287Posix From the IEEE standard 1003.2, Part 2: Shell and utilities.
288 Generally known as "Posix". This is a textual description of
289 how Vi is supposed to work.
Bram Moolenaar7c626922005-02-07 22:01:03 +0000290 See |posix-compliance|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000291 *Nvi*
292Nvi The "New" Vi. The version of Vi that comes with BSD 4.4 and FreeBSD.
293 Very good compatibility with the original Vi, with a few extensions.
294 The version used is 1.79. ":version" returns "Version 1.79
295 (10/23/96)". There has been no release the last few years, although
296 there is a development version 1.81.
297 Source code is freely available.
298 *Elvis*
299Elvis Another Vi clone, made by Steve Kirkendall. Very compact but isn't
300 as flexible as Vim.
301 The version used is 2.1. It is still being developed. Source code is
302 freely available.
303
304==============================================================================
3054. Notation *notation*
306
307When syntax highlighting is used to read this, text that is not typed
308literally is often highlighted with the Special group. These are items in [],
309{} and <>, and CTRL-X.
310
311Note that Vim uses all possible characters in commands. Sometimes the [], {}
312and <> are part of what you type, the context should make this clear.
313
314
315[] Characters in square brackets are optional.
316
Bram Moolenaar4a748032010-09-30 21:47:56 +0200317 *count* *[count]*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318[count] An optional number that may precede the command to multiply
319 or iterate the command. If no number is given, a count of one
320 is used, unless otherwise noted. Note that in this manual the
321 [count] is not mentioned in the description of the command,
322 but only in the explanation. This was done to make the
323 commands easier to look up. If the 'showcmd' option is on,
324 the (partially) entered count is shown at the bottom of the
325 window. You can use <Del> to erase the last digit (|N<Del>|).
326
327 *[quotex]*
328["x] An optional register designation where text can be stored.
329 See |registers|. The x is a single character between 'a' and
330 'z' or 'A' and 'Z' or '"', and in some cases (with the put
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000331 command) between '0' and '9', '%', '#', or others. The
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332 uppercase and lowercase letter designate the same register,
333 but the lowercase letter is used to overwrite the previous
334 register contents, while the uppercase letter is used to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000335 append to the previous register contents. Without the ""x" or
Bram Moolenaar071d4272004-06-13 20:20:40 +0000336 with """" the stored text is put into the unnamed register.
337
338 *{}*
339{} Curly braces denote parts of the command which must appear,
340 but which can take a number of different values. The
341 differences between Vim and Vi are also given in curly braces
342 (this will be clear from the context).
343
344 *{char1-char2}*
345{char1-char2} A single character from the range char1 to char2. For
346 example: {a-z} is a lowercase letter. Multiple ranges may be
347 concatenated. For example, {a-zA-Z0-9} is any alphanumeric
348 character.
349
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000350 *{motion}* *movement*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351{motion} A command that moves the cursor. These are explained in
352 |motion.txt|. Examples:
353 w to start of next word
354 b to begin of current word
355 4j four lines down
356 /The<CR> to next occurrence of "The"
357 This is used after an |operator| command to move over the text
358 that is to be operated upon.
359 - If the motion includes a count and the operator also has a
360 count, the two counts are multiplied. For example: "2d3w"
361 deletes six words.
362 - The motion can be backwards, e.g. "db" to delete to the
363 start of the word.
364 - The motion can also be a mouse click. The mouse is not
365 supported in every terminal though.
366 - The ":omap" command can be used to map characters while an
367 operator is pending.
368 - Ex commands can be used to move the cursor. This can be
369 used to call a function that does some complicated motion.
370 The motion is always characterwise exclusive, no matter
371 what ":" command is used. This means it's impossible to
372 include the last character of a line without the line break
373 (unless 'virtualedit' is set).
374 If the Ex command changes the text before where the operator
375 starts or jumps to another buffer the result is
376 unpredictable. It is possible to change the text further
377 down. Jumping to another buffer is possible if the current
378 buffer is not unloaded.
379
380 *{Visual}*
381{Visual} A selected text area. It is started with the "v", "V", or
382 CTRL-V command, then any cursor movement command can be used
383 to change the end of the selected text.
384 This is used before an |operator| command to highlight the
385 text that is to be operated upon.
386 See |Visual-mode|.
387
388 *<character>*
389<character> A special character from the table below, optionally with
390 modifiers, or a single ASCII character with modifiers.
391
392 *'character'*
393'c' A single ASCII character.
394
395 *CTRL-{char}*
396CTRL-{char} {char} typed as a control character; that is, typing {char}
397 while holding the CTRL key down. The case of {char} does not
398 matter; thus CTRL-A and CTRL-a are equivalent. But on some
399 terminals, using the SHIFT key will produce another code,
400 don't use it then.
401
402 *'option'*
403'option' An option, or parameter, that can be set to a value, is
404 enclosed in single quotes. See |options|.
405
406 *quotecommandquote*
407"command" A reference to a command that you can type is enclosed in
408 double quotes.
Bram Moolenaar00154502013-02-13 16:15:55 +0100409`command` New style command, this distinguishes it from other quoted
410 text and strings.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411
412 *key-notation* *key-codes* *keycodes*
413These names for keys are used in the documentation. They can also be used
414with the ":map" command (insert the key name by pressing CTRL-K and then the
415key you want the name for).
416
417notation meaning equivalent decimal value(s) ~
418-----------------------------------------------------------------------
419<Nul> zero CTRL-@ 0 (stored as 10) *<Nul>*
420<BS> backspace CTRL-H 8 *backspace*
421<Tab> tab CTRL-I 9 *tab* *Tab*
422 *linefeed*
423<NL> linefeed CTRL-J 10 (used for <Nul>)
424<FF> formfeed CTRL-L 12 *formfeed*
425<CR> carriage return CTRL-M 13 *carriage-return*
426<Return> same as <CR> *<Return>*
427<Enter> same as <CR> *<Enter>*
428<Esc> escape CTRL-[ 27 *escape* *<Esc>*
429<Space> space 32 *space*
430<lt> less-than < 60 *<lt>*
431<Bslash> backslash \ 92 *backslash* *<Bslash>*
432<Bar> vertical bar | 124 *<Bar>*
433<Del> delete 127
434<CSI> command sequence intro ALT-Esc 155 *<CSI>*
435<xCSI> CSI when typed in the GUI *<xCSI>*
436
437<EOL> end-of-line (can be <CR>, <LF> or <CR><LF>,
438 depends on system and 'fileformat') *<EOL>*
439
440<Up> cursor-up *cursor-up* *cursor_up*
441<Down> cursor-down *cursor-down* *cursor_down*
442<Left> cursor-left *cursor-left* *cursor_left*
443<Right> cursor-right *cursor-right* *cursor_right*
444<S-Up> shift-cursor-up
445<S-Down> shift-cursor-down
446<S-Left> shift-cursor-left
447<S-Right> shift-cursor-right
448<C-Left> control-cursor-left
449<C-Right> control-cursor-right
450<F1> - <F12> function keys 1 to 12 *function_key* *function-key*
451<S-F1> - <S-F12> shift-function keys 1 to 12 *<S-F1>*
452<Help> help key
453<Undo> undo key
454<Insert> insert key
455<Home> home *home*
456<End> end *end*
457<PageUp> page-up *page_up* *page-up*
458<PageDown> page-down *page_down* *page-down*
459<kHome> keypad home (upper left) *keypad-home*
460<kEnd> keypad end (lower left) *keypad-end*
461<kPageUp> keypad page-up (upper right) *keypad-page-up*
462<kPageDown> keypad page-down (lower right) *keypad-page-down*
463<kPlus> keypad + *keypad-plus*
464<kMinus> keypad - *keypad-minus*
465<kMultiply> keypad * *keypad-multiply*
466<kDivide> keypad / *keypad-divide*
467<kEnter> keypad Enter *keypad-enter*
468<kPoint> keypad Decimal point *keypad-point*
469<k0> - <k9> keypad 0 to 9 *keypad-0* *keypad-9*
470<S-...> shift-key *shift* *<S-*
471<C-...> control-key *control* *ctrl* *<C-*
472<M-...> alt-key or meta-key *meta* *alt* *<M-*
473<A-...> same as <M-...> *<A-*
474<D-...> command-key (Macintosh only) *<D-*
475<t_xx> key with "xx" entry in termcap
476-----------------------------------------------------------------------
477
478Note: The shifted cursor keys, the help key, and the undo key are only
479available on a few terminals. On the Amiga, shifted function key 10 produces
480a code (CSI) that is also used by key sequences. It will be recognized only
481after typing another key.
482
483Note: There are two codes for the delete key. 127 is the decimal ASCII value
484for the delete key, which is always recognized. Some delete keys send another
485value, in which case this value is obtained from the termcap entry "kD". Both
486values have the same effect. Also see |:fixdel|.
487
488Note: The keypad keys are used in the same way as the corresponding "normal"
489keys. For example, <kHome> has the same effect as <Home>. If a keypad key
490sends the same raw key code as its non-keypad equivalent, it will be
491recognized as the non-keypad code. For example, when <kHome> sends the same
492code as <Home>, when pressing <kHome> Vim will think <Home> was pressed.
493Mapping <kHome> will not work then.
494
495 *<>*
496Examples are often given in the <> notation. Sometimes this is just to make
497clear what you need to type, but often it can be typed literally, e.g., with
498the ":map" command. The rules are:
499 1. Any printable characters are typed directly, except backslash and '<'
500 2. A backslash is represented with "\\", double backslash, or "<Bslash>".
501 3. A real '<' is represented with "\<" or "<lt>". When there is no
502 confusion possible, a '<' can be used directly.
503 4. "<key>" means the special key typed. This is the notation explained in
504 the table above. A few examples:
505 <Esc> Escape key
506 <C-G> CTRL-G
507 <Up> cursor up key
508 <C-LeftMouse> Control- left mouse click
509 <S-F11> Shifted function key 11
510 <M-a> Meta- a ('a' with bit 8 set)
511 <M-A> Meta- A ('A' with bit 8 set)
512 <t_kd> "kd" termcap entry (cursor down key)
513
514If you want to use the full <> notation in Vim, you have to make sure the '<'
515flag is excluded from 'cpoptions' (when 'compatible' is not set, it already is
516by default). >
517 :set cpo-=<
518The <> notation uses <lt> to escape the special meaning of key names. Using a
519backslash also works, but only when 'cpoptions' does not include the 'B' flag.
520
521Examples for mapping CTRL-H to the six characters "<Home>": >
522 :imap <C-H> \<Home>
523 :imap <C-H> <lt>Home>
524The first one only works when the 'B' flag is not in 'cpoptions'. The second
525one always works.
526To get a literal "<lt>" in a mapping: >
527 :map <C-L> <lt>lt>
528
529For mapping, abbreviation and menu commands you can then copy-paste the
530examples and use them directly. Or type them literally, including the '<' and
531'>' characters. This does NOT work for other commands, like ":set" and
532":autocmd"!
533
534==============================================================================
5355. Modes, introduction *vim-modes-intro* *vim-modes*
536
Bram Moolenaar1ccd8ff2017-08-11 19:50:37 +0200537Vim has seven BASIC modes:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538
539 *Normal* *Normal-mode* *command-mode*
540Normal mode In Normal mode you can enter all the normal editor
541 commands. If you start the editor you are in this
542 mode (unless you have set the 'insertmode' option,
543 see below). This is also known as command mode.
544
545Visual mode This is like Normal mode, but the movement commands
546 extend a highlighted area. When a non-movement
547 command is used, it is executed for the highlighted
548 area. See |Visual-mode|.
549 If the 'showmode' option is on "-- VISUAL --" is shown
550 at the bottom of the window.
551
552Select mode This looks most like the MS-Windows selection mode.
553 Typing a printable character deletes the selection
554 and starts Insert mode. See |Select-mode|.
555 If the 'showmode' option is on "-- SELECT --" is shown
556 at the bottom of the window.
557
558Insert mode In Insert mode the text you type is inserted into the
559 buffer. See |Insert-mode|.
560 If the 'showmode' option is on "-- INSERT --" is shown
561 at the bottom of the window.
562
563Command-line mode In Command-line mode (also called Cmdline mode) you
564Cmdline mode can enter one line of text at the bottom of the
565 window. This is for the Ex commands, ":", the pattern
566 search commands, "?" and "/", and the filter command,
567 "!". |Cmdline-mode|
568
569Ex mode Like Command-line mode, but after entering a command
570 you remain in Ex mode. Very limited editing of the
571 command line. |Ex-mode|
572
Bram Moolenaar1ccd8ff2017-08-11 19:50:37 +0200573Terminal-Job mode Interacting with a job in a terminal window. Typed
574 keys go to the job and the job output is displayed in
575 the terminal window. See |terminal| about how to
576 switch to other modes.
577
Bram Moolenaarf55e4c82017-08-01 20:44:53 +0200578There are seven ADDITIONAL modes. These are variants of the BASIC modes:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579
580 *Operator-pending* *Operator-pending-mode*
581Operator-pending mode This is like Normal mode, but after an operator
582 command has started, and Vim is waiting for a {motion}
583 to specify the text that the operator will work on.
584
585Replace mode Replace mode is a special case of Insert mode. You
586 can do the same things as in Insert mode, but for
587 each character you enter, one character of the existing
588 text is deleted. See |Replace-mode|.
589 If the 'showmode' option is on "-- REPLACE --" is
590 shown at the bottom of the window.
591
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000592Virtual Replace mode Virtual Replace mode is similar to Replace mode, but
593 instead of file characters you are replacing screen
594 real estate. See |Virtual-Replace-mode|.
595 If the 'showmode' option is on "-- VREPLACE --" is
596 shown at the bottom of the window.
597
Bram Moolenaard473c8c2018-08-11 18:00:22 +0200598Insert Normal mode Entered when CTRL-O is typed in Insert mode (see
599 |i_CTRL-O|). This is like Normal mode, but after
600 executing one command Vim returns to Insert mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 If the 'showmode' option is on "-- (insert) --" is
602 shown at the bottom of the window.
603
Bram Moolenaar1ccd8ff2017-08-11 19:50:37 +0200604Terminal-Normal mode Using Normal mode in a terminal window. Making
605 changes is impossible. Use an insert command, such as
606 "a" or "i", to return to Terminal-Job mode.
Bram Moolenaarf55e4c82017-08-01 20:44:53 +0200607
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608Insert Visual mode Entered when starting a Visual selection from Insert
609 mode, e.g., by using CTRL-O and then "v", "V" or
610 CTRL-V. When the Visual selection ends, Vim returns
611 to Insert mode.
612 If the 'showmode' option is on "-- (insert) VISUAL --"
613 is shown at the bottom of the window.
614
615Insert Select mode Entered when starting Select mode from Insert mode.
616 E.g., by dragging the mouse or <S-Right>.
617 When the Select mode ends, Vim returns to Insert mode.
618 If the 'showmode' option is on "-- (insert) SELECT --"
619 is shown at the bottom of the window.
620
621==============================================================================
6226. Switching from mode to mode *mode-switching*
623
624If for any reason you do not know which mode you are in, you can always get
625back to Normal mode by typing <Esc> twice. This doesn't work for Ex mode
626though, use ":visual".
627You will know you are back in Normal mode when you see the screen flash or
628hear the bell after you type <Esc>. However, when pressing <Esc> after using
629CTRL-O in Insert mode you get a beep but you are still in Insert mode, type
630<Esc> again.
631
632 *i_esc*
633 TO mode ~
634 Normal Visual Select Insert Replace Cmd-line Ex ~
635FROM mode ~
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000636Normal v V ^V *4 *1 R gR : / ? ! Q
Bram Moolenaar071d4272004-06-13 20:20:40 +0000637Visual *2 ^G c C -- : --
638Select *5 ^O ^G *6 -- -- --
639Insert <Esc> -- -- <Insert> -- --
640Replace <Esc> -- -- <Insert> -- --
641Command-line *3 -- -- :start -- --
642Ex :vi -- -- -- -- --
643
Bram Moolenaar071d4272004-06-13 20:20:40 +0000644-- not possible
645
646*1 Go from Normal mode to Insert mode by giving the command "i", "I", "a",
647 "A", "o", "O", "c", "C", "s" or S".
648*2 Go from Visual mode to Normal mode by giving a non-movement command, which
649 causes the command to be executed, or by hitting <Esc> "v", "V" or "CTRL-V"
650 (see |v_v|), which just stops Visual mode without side effects.
651*3 Go from Command-line mode to Normal mode by:
652 - Hitting <CR> or <NL>, which causes the entered command to be executed.
653 - Deleting the complete line (e.g., with CTRL-U) and giving a final <BS>.
654 - Hitting CTRL-C or <Esc>, which quits the command-line without executing
655 the command.
656 In the last case <Esc> may be the character defined with the 'wildchar'
657 option, in which case it will start command-line completion. You can
658 ignore that and type <Esc> again. {Vi: when hitting <Esc> the command-line
659 is executed. This is unexpected for most people; therefore it was changed
660 in Vim. But when the <Esc> is part of a mapping, the command-line is
661 executed. If you want the Vi behaviour also when typing <Esc>, use ":cmap
662 ^V<Esc> ^V^M"}
663*4 Go from Normal to Select mode by:
664 - use the mouse to select text while 'selectmode' contains "mouse"
665 - use a non-printable command to move the cursor while keeping the Shift
666 key pressed, and the 'selectmode' option contains "key"
667 - use "v", "V" or "CTRL-V" while 'selectmode' contains "cmd"
668 - use "gh", "gH" or "g CTRL-H" |g_CTRL-H|
669*5 Go from Select mode to Normal mode by using a non-printable command to move
670 the cursor, without keeping the Shift key pressed.
671*6 Go from Select mode to Insert mode by typing a printable character. The
672 selection is deleted and the character is inserted.
673
674If the 'insertmode' option is on, editing a file will start in Insert mode.
675
676 *CTRL-\_CTRL-N* *i_CTRL-\_CTRL-N* *c_CTRL-\_CTRL-N* *v_CTRL-\_CTRL-N*
677Additionally the command CTRL-\ CTRL-N or <C-\><C-N> can be used to go to
678Normal mode from any other mode. This can be used to make sure Vim is in
679Normal mode, without causing a beep like <Esc> would. However, this does not
680work in Ex mode. When used after a command that takes an argument, such as
681|f| or |m|, the timeout set with 'ttimeoutlen' applies.
Bram Moolenaar1ccd8ff2017-08-11 19:50:37 +0200682When focus is in a terminal window, CTRL-\ CTRL-N goes to Normal mode for only
683one command, see |t_CTRL-\_CTRL-N|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000684
685 *CTRL-\_CTRL-G* *i_CTRL-\_CTRL-G* *c_CTRL-\_CTRL-G* *v_CTRL-\_CTRL-G*
686The command CTRL-\ CTRL-G or <C-\><C-G> can be used to go to Insert mode when
687'insertmode' is set. Otherwise it goes to Normal mode. This can be used to
688make sure Vim is in the mode indicated by 'insertmode', without knowing in
689what mode Vim currently is.
690
691 *Q* *mode-Ex* *Ex-mode* *Ex* *EX* *E501*
692Q Switch to "Ex" mode. This is a bit like typing ":"
693 commands one after another, except:
694 - You don't have to keep pressing ":".
695 - The screen doesn't get updated after each command.
696 - There is no normal command-line editing.
697 - Mappings and abbreviations are not used.
698 In fact, you are editing the lines with the "standard"
699 line-input editing commands (<Del> or <BS> to erase,
700 CTRL-U to kill the whole line).
701 Vim will enter this mode by default if it's invoked as
702 "ex" on the command-line.
703 Use the ":vi" command |:visual| to exit "Ex" mode.
704 Note: In older versions of Vim "Q" formatted text,
705 that is now done with |gq|. But if you use the
706 |vimrc_example.vim| script "Q" works like "gq".
707
708 *gQ*
Bram Moolenaar7c626922005-02-07 22:01:03 +0000709gQ Switch to "Ex" mode like with "Q", but really behave
710 like typing ":" commands after another. All command
711 line editing, completion etc. is available.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000712 Use the ":vi" command |:visual| to exit "Ex" mode.
713 {not in Vi}
714
715==============================================================================
7167. The window contents *window-contents*
717
718In Normal mode and Insert/Replace mode the screen window will show the current
719contents of the buffer: What You See Is What You Get. There are two
720exceptions:
721- When the 'cpoptions' option contains '$', and the change is within one line,
722 the text is not directly deleted, but a '$' is put at the last deleted
723 character.
724- When inserting text in one window, other windows on the same text are not
725 updated until the insert is finished.
726{Vi: The screen is not always updated on slow terminals}
727
728Lines longer than the window width will wrap, unless the 'wrap' option is off
729(see below). The 'linebreak' option can be set to wrap at a blank character.
730
731If the window has room after the last line of the buffer, Vim will show '~' in
Bram Moolenaar166af9b2010-11-16 20:34:40 +0100732the first column of the last lines in the window, like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733
734 +-----------------------+
735 |some line |
736 |last line |
737 |~ |
738 |~ |
739 +-----------------------+
740
741Thus the '~' lines indicate that the end of the buffer was reached.
742
743If the last line in a window doesn't fit, Vim will indicate this with a '@' in
Bram Moolenaar166af9b2010-11-16 20:34:40 +0100744the first column of the last lines in the window, like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745
746 +-----------------------+
747 |first line |
748 |second line |
749 |@ |
750 |@ |
751 +-----------------------+
752
753Thus the '@' lines indicate that there is a line that doesn't fit in the
754window.
755
756When the "lastline" flag is present in the 'display' option, you will not see
757'@' characters at the left side of window. If the last line doesn't fit
758completely, only the part that fits is shown, and the last three characters of
Bram Moolenaar81af9252010-12-10 20:35:50 +0100759the last line are replaced with "@@@", like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760
761 +-----------------------+
762 |first line |
763 |second line |
764 |a very long line that d|
765 |oesn't fit in the wi@@@|
766 +-----------------------+
767
768If there is a single line that is too long to fit in the window, this is a
769special situation. Vim will show only part of the line, around where the
770cursor is. There are no special characters shown, so that you can edit all
771parts of this line.
772{Vi: gives an "internal error" on lines that do not fit in the window}
773
774The '@' occasion in the 'highlight' option can be used to set special
775highlighting for the '@' and '~' characters. This makes it possible to
776distinguish them from real characters in the buffer.
777
778The 'showbreak' option contains the string to put in front of wrapped lines.
779
780 *wrap-off*
781If the 'wrap' option is off, long lines will not wrap. Only the part that
782fits on the screen is shown. If the cursor is moved to a part of the line
783that is not shown, the screen is scrolled horizontally. The advantage of
784this method is that columns are shown as they are and lines that cannot fit
785on the screen can be edited. The disadvantage is that you cannot see all the
786characters of a line at once. The 'sidescroll' option can be set to the
787minimal number of columns to scroll. {Vi: has no 'wrap' option}
788
789All normal ASCII characters are displayed directly on the screen. The <Tab>
790is replaced with the number of spaces that it represents. Other non-printing
791characters are replaced with "^{char}", where {char} is the non-printing
792character with 64 added. Thus character 7 (bell) will be shown as "^G".
793Characters between 127 and 160 are replaced with "~{char}", where {char} is
794the character with 64 subtracted. These characters occupy more than one
795position on the screen. The cursor can only be positioned on the first one.
796
797If you set the 'number' option, all lines will be preceded with their
798number. Tip: If you don't like wrapping lines to mix with the line numbers,
799set the 'showbreak' option to eight spaces:
800 ":set showbreak=\ \ \ \ \ \ \ \ "
801
802If you set the 'list' option, <Tab> characters will not be shown as several
803spaces, but as "^I". A '$' will be placed at the end of the line, so you can
804find trailing blanks.
805
806In Command-line mode only the command-line itself is shown correctly. The
807display of the buffer contents is updated as soon as you go back to Command
808mode.
809
810The last line of the window is used for status and other messages. The
811status messages will only be used if an option is on:
812
813status message option default Unix default ~
814current mode 'showmode' on on
815command characters 'showcmd' on off
816cursor position 'ruler' off off
817
818The current mode is "-- INSERT --" or "-- REPLACE --", see |'showmode'|. The
819command characters are those that you typed but were not used yet. {Vi: does
820not show the characters you typed or the cursor position}
821
822If you have a slow terminal you can switch off the status messages to speed
823up editing:
824 :set nosc noru nosm
825
826If there is an error, an error message will be shown for at least one second
827(in reverse video). {Vi: error messages may be overwritten with other
828messages before you have a chance to read them}
829
830Some commands show how many lines were affected. Above which threshold this
831happens can be controlled with the 'report' option (default 2).
832
833On the Amiga Vim will run in a CLI window. The name Vim and the full name of
834the current file name will be shown in the title bar. When the window is
835resized, Vim will automatically redraw the window. You may make the window as
836small as you like, but if it gets too small not a single line will fit in it.
837Make it at least 40 characters wide to be able to read most messages on the
838last line.
839
840On most Unix systems, resizing the window is recognized and handled correctly
841by Vim. {Vi: not ok}
842
843==============================================================================
8448. Definitions *definitions*
845
Bram Moolenaarc572da52017-08-27 16:52:01 +0200846 buffer Contains lines of text, usually read from a file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 screen The whole area that Vim uses to work in. This can be
848 a terminal emulator window. Also called "the Vim
849 window".
Bram Moolenaarc572da52017-08-27 16:52:01 +0200850 window A view on a buffer. There can be multiple windows for
851 one buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852
853A screen contains one or more windows, separated by status lines and with the
854command line at the bottom.
855
856 +-------------------------------+
857screen | window 1 | window 2 |
858 | | |
859 | | |
860 |= status line =|= status line =|
861 | window 3 |
862 | |
863 | |
864 |==== status line ==============|
865 |command line |
866 +-------------------------------+
867
868The command line is also used for messages. It scrolls up the screen when
869there is not enough room in the command line.
870
871A difference is made between four types of lines:
872
873 buffer lines The lines in the buffer. This is the same as the
874 lines as they are read from/written to a file. They
875 can be thousands of characters long.
876 logical lines The buffer lines with folding applied. Buffer lines
877 in a closed fold are changed to a single logical line:
878 "+-- 99 lines folded". They can be thousands of
879 characters long.
880 window lines The lines displayed in a window: A range of logical
881 lines with wrapping, line breaks, etc. applied. They
882 can only be as long as the width of the window allows,
883 longer lines are wrapped or truncated.
884 screen lines The lines of the screen that Vim uses. Consists of
885 the window lines of all windows, with status lines
886 and the command line added. They can only be as long
887 as the width of the screen allows. When the command
888 line gets longer it wraps and lines are scrolled to
889 make room.
890
891buffer lines logical lines window lines screen lines ~
892
8931. one 1. one 1. +-- folded 1. +-- folded
8942. two 2. +-- folded 2. five 2. five
8953. three 3. five 3. six 3. six
8964. four 4. six 4. seven 4. seven
8975. five 5. seven 5. === status line ===
8986. six 6. aaa
8997. seven 7. bbb
900 8. ccc ccc c
9011. aaa 1. aaa 1. aaa 9. cc
9022. bbb 2. bbb 2. bbb 10. ddd
9033. ccc ccc ccc 3. ccc ccc ccc 3. ccc ccc c 11. ~
9044. ddd 4. ddd 4. cc 12. === status line ===
905 5. ddd 13. (command line)
906 6. ~
907
908==============================================================================
Bram Moolenaar91f84f62018-07-29 15:07:52 +0200909 vim:tw=78:ts=8:noet:ft=help:norl: