blob: f4ddb0876c10f6989b4d2dc5f18d05ac0338d5d3 [file] [log] [blame]
Christian Brabandt596ad662023-08-16 00:11:09 +02001*intro.txt* For Vim version 9.0. Last change: 2023 Aug 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
Bram Moolenaar25c9c682019-05-05 18:13:34 +020037The differences between Vi and Vim are mentioned in |vi_diff.txt|.
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
39This manual refers to Vim on various machines. There may be small differences
40between different computers and terminals. Besides the remarks given in this
41document, there is a separate document for each supported system, see
42|sys-file-list|.
43
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +010044 *pronounce*
45Vim is pronounced as one word, like Jim, not vi-ai-em. It's written with a
46capital, since it's a name, again like Jim.
47
Bram Moolenaar071d4272004-06-13 20:20:40 +000048This manual is a reference for all the Vim commands and options. This is not
49an introduction to the use of Vi or Vim, it gets a bit complicated here and
50there. For beginners, there is a hands-on |tutor|. To learn using Vim, read
51the user manual |usr_toc.txt|.
52
Bram Moolenaar4c05fa02019-01-01 15:32:17 +010053 *book* *books*
54Most books on Vi and Vim contain a section for beginners. Others are spending
55more words on specific functionality. You can find an overview of Vim books
56here:
57 http://iccf-holland.org/vim_books.html
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
59==============================================================================
602. Vim on the internet *internet*
61
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000062 *www* *WWW* *faq* *FAQ* *distribution* *download*
Bram Moolenaar071d4272004-06-13 20:20:40 +000063The Vim pages contain the most recent information about Vim. They also
64contain links to the most recent version of Vim. The FAQ is a list of
65Frequently Asked Questions. Read this if you have problems.
66
Bram Moolenaar4c05fa02019-01-01 15:32:17 +010067 Vim home page: https://www.vim.org/
Bram Moolenaar6c1e1572019-06-22 02:13:00 +020068 Vim FAQ: https://vimhelp.org/vim_faq.txt.html
Bram Moolenaar4c05fa02019-01-01 15:32:17 +010069 Downloading: https://www.vim.org/download.php
Bram Moolenaar071d4272004-06-13 20:20:40 +000070
71
Bram Moolenaar790c18b2019-07-04 17:22:06 +020072Asking questions, finding answers: https://vi.stackexchange.com/
73"Vi and Vim Stack Exchange is a question and answer site for people using the
74vi and Vim families of text editors"
75
76
Bram Moolenaar071d4272004-06-13 20:20:40 +000077Usenet News group where Vim is discussed: *news* *usenet*
78 comp.editors
79This group is also for other editors. If you write about Vim, don't forget to
80mention that.
Bram Moolenaar790c18b2019-07-04 17:22:06 +020081You can access it here:
82https://groups.google.com/forum/#!topic/comp.editors
Bram Moolenaar071d4272004-06-13 20:20:40 +000083
84 *mail-list* *maillist*
85There are several mailing lists for Vim:
Bram Moolenaar68563932017-01-10 13:31:15 +010086<vim@vim.org> *vim-use* *vim_use*
Bram Moolenaar071d4272004-06-13 20:20:40 +000087 For discussions about using existing versions of Vim: Useful mappings,
Bram Moolenaarc6fe9192006-04-09 21:54:49 +000088 questions, answers, where to get a specific version, etc. There are
89 quite a few people watching this list and answering questions, also
90 for beginners. Don't hesitate to ask your question here.
Bram Moolenaar68563932017-01-10 13:31:15 +010091<vim-dev@vim.org> *vim-dev* *vim_dev* *vimdev*
Bram Moolenaar071d4272004-06-13 20:20:40 +000092 For discussions about changing Vim: New features, porting, patches,
93 beta-test versions, etc.
Bram Moolenaar68563932017-01-10 13:31:15 +010094<vim-announce@vim.org> *vim-announce* *vim_announce*
Bram Moolenaar071d4272004-06-13 20:20:40 +000095 Announcements about new versions of Vim; also for beta-test versions
Bram Moolenaarc6fe9192006-04-09 21:54:49 +000096 and ports to different systems. This is a read-only list.
Bram Moolenaar68563932017-01-10 13:31:15 +010097<vim-mac@vim.org> *vim-mac* *vim_mac*
Bram Moolenaar071d4272004-06-13 20:20:40 +000098 For discussions about using and improving the Macintosh version of
99 Vim.
100
101See http://www.vim.org/maillist.php for the latest information.
102
103NOTE:
Bram Moolenaar4c05fa02019-01-01 15:32:17 +0100104- Anyone can see the archive, e.g. on Google groups. Search this if you have
105 questions.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106- You can only send messages to these lists if you have subscribed!
Bram Moolenaar4c05fa02019-01-01 15:32:17 +0100107- The first message is moderated, thus it may take a few hours to show up.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108- You need to send the messages from the same location as where you subscribed
109 from (to avoid spam mail).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110
111 *subscribe-maillist*
112If you want to join, send a message to
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000113 <vim-subscribe@vim.org>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114Make sure that your "From:" address is correct. Then the list server will
115give you help on how to subscribe.
116
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000117 *maillist-archive*
118For more information and archives look on the Vim maillist page:
119http://www.vim.org/maillist.php
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120
121
122Bug reports: *bugs* *bug-reports* *bugreport.vim*
123
Bram Moolenaaracc22402020-06-07 21:07:18 +0200124There are three ways to report bugs:
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001251. For issues with runtime files, look in the header for an email address or
Bram Moolenaaracc22402020-06-07 21:07:18 +0200126 any other way to report it to the maintainer.
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001272. Open an issue on GitHub: https://github.com/vim/vim/issues
128 The text will be forwarded to the vim-dev maillist.
Bram Moolenaaracc22402020-06-07 21:07:18 +02001293. Send bug reports to: Vim Developers <vim-dev@vim.org>
Bram Moolenaar3e496b02016-09-25 22:11:48 +0200130 This is a maillist, you need to become a member first and many people will
131 see the message. If you don't want that, e.g. because it is a security
Christian Brabandte978b452023-08-13 10:33:05 +0200132 issue, please contact any of the current Vim maintainers
133 https://github.com/orgs/vim/people (but not Bram or the vim-dev ML).
134 In the future, a proper process for handling security issues will be setup.
Bram Moolenaar822ff862014-06-12 21:46:14 +0200135
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136Please be brief; all the time that is spent on answering mail is subtracted
137from the time that is spent on improving Vim! Always give a reproducible
Bram Moolenaarb6e0ec62017-07-23 22:12:20 +0200138example and try to find out which settings or other things trigger the bug.
139
140Preferably start Vim with: >
141 vim --clean -u reproduce.vim
142Where reproduce.vim is a script that reproduces the problem. Try different
143machines, if relevant (is this an MS-Windows specific bug perhaps?).
144
Bram Moolenaar4c05fa02019-01-01 15:32:17 +0100145Send me patches if you can! If you create a pull request on
146https://github.com/vim/vim then the automated checks will run and report any
147obvious problems. But you can also send the patch by email (use an attachment
148to avoid white space changes).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000149
Bram Moolenaare344bea2005-09-01 20:46:49 +0000150It will help to include information about the version of Vim you are using and
151your setup. You can get the information with this command: >
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152 :so $VIMRUNTIME/bugreport.vim
153This will create a file "bugreport.txt" in the current directory, with a lot
154of information of your environment. Before sending this out, check if it
155doesn't contain any confidential information!
156
Bram Moolenaare344bea2005-09-01 20:46:49 +0000157If Vim crashes, please try to find out where. You can find help on this here:
158|debug.txt|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000159
Bram Moolenaare344bea2005-09-01 20:46:49 +0000160In case of doubt or when you wonder if the problem has already been fixed but
161you can't find a fix for it, become a member of the vim-dev maillist and ask
162your question there. |maillist|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163
164 *year-2000* *Y2K*
165Since Vim internally doesn't use dates for editing, there is no year 2000
166problem to worry about. Vim does use the time in the form of seconds since
167January 1st 1970. It is used for a time-stamp check of the edited file and
168the swap file, which is not critical and should only cause warning messages.
169
170There might be a year 2038 problem, when the seconds don't fit in a 32 bit int
171anymore. This depends on the compiler, libraries and operating system.
172Specifically, time_t and the ctime() function are used. And the time_t is
173stored in four bytes in the swap file. But that's only used for printing a
174file date/time for recovery, it will never affect normal editing.
175
176The Vim strftime() function directly uses the strftime() system function.
177localtime() uses the time() system function. getftime() uses the time
178returned by the stat() system function. If your system libraries are year
1792000 compliant, Vim is too.
180
181The user may create scripts for Vim that use external commands. These might
182introduce Y2K problems, but those are not really part of Vim itself.
183
184==============================================================================
Christian Brabandte978b452023-08-13 10:33:05 +02001853. Credits *credits* *author*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000186
h_east59858792023-10-25 22:47:05 +0900187Most of Vim was created by Bram Moolenaar <Bram@vim.org> |Bram-Moolenaar|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188
189Parts of the documentation come from several Vi manuals, written by:
190 W.N. Joy
191 Alan P.W. Hewett
192 Mark Horton
193
194The Vim editor is based on Stevie and includes (ideas from) other software,
195worked on by the people mentioned here. Other people helped by sending me
196patches, suggestions and giving feedback about what is good and bad in Vim.
197
198Vim would never have become what it is now, without the help of these people!
199
200 Ron Aaron Win32 GUI changes
Bram Moolenaar91604412010-06-03 20:25:18 +0200201 Mohsin Ahmed encryption
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202 Zoltan Arpadffy work on VMS port
203 Tony Andrews Stevie
204 Gert van Antwerpen changes for DJGPP on MS-DOS
205 Berkeley DB(3) ideas for swap file implementation
206 Keith Bostic Nvi
207 Walter Briscoe Makefile updates, various patches
208 Ralf Brown SPAWNO library for MS-DOS
209 Robert Colon many useful remarks
210 Marcin Dalecki GTK+ GUI port, toolbar icons, gettext()
211 Kayhan Demirel sent me news in Uganda
212 Chris & John Downey xvi (ideas for multi-windows version)
213 Henk Elbers first VMS port
Bram Moolenaar7b0294c2004-10-11 10:16:09 +0000214 Daniel Elstner GTK+ 2 port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000215 Eric Fischer Mac port, 'cindent', and other improvements
216 Benji Fisher Answering lots of user questions
Bram Moolenaarcbaff5e2022-04-08 17:45:08 +0100217 Bill Foster Athena GUI port (later removed)
Christian Brabandt596ad662023-08-16 00:11:09 +0200218 Google Let Bram work on Vim one day a week
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219 Loic Grenie xvim (ideas for multi windows version)
h_east59858792023-10-25 22:47:05 +0900220 Sven Guckes Vim promoter and previous WWW page maintainer
221 |Sven-Guckes|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222 Darren Hiebert Exuberant ctags
Bram Moolenaar7b0294c2004-10-11 10:16:09 +0000223 Jason Hildebrand GTK+ 2 port
Bram Moolenaar071d4272004-06-13 20:20:40 +0000224 Bruce Hunsaker improvements for VMS port
225 Andy Kahn Cscope support, GTK+ GUI port
226 Oezguer Kesim Maintainer of Vim Mailing Lists
227 Axel Kielhorn work on the Macintosh port
228 Steve Kirkendall Elvis
229 Roger Knobbe original port to Windows NT
230 Sergey Laskavy Vim's help from Moscow
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000231 Felix von Leitner Previous maintainer of Vim Mailing Lists
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232 David Leonard Port of Python extensions to Unix
233 Avner Lottem Edit in right-to-left windows
234 Flemming Madsen X11 client-server, various features and patches
Bram Moolenaar91604412010-06-03 20:25:18 +0200235 Tony Mechelynck answers many user questions
Bram Moolenaar071d4272004-06-13 20:20:40 +0000236 Paul Moore Python interface extensions, many patches
Bram Moolenaar207f0092020-08-30 17:20:20 +0200237 Katsuhito Nagano Work on multibyte versions
238 Sung-Hyun Nam Work on multibyte versions
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239 Vince Negri Win32 GUI and generic console enhancements
240 Steve Oualline Author of the first Vim book |frombook|
Bram Moolenaar574ee7b2019-11-13 23:04:29 +0100241 Dominique Pelle Valgrind reports and many fixes
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000242 A.Politz Many bug reports and some fixes
Bram Moolenaar071d4272004-06-13 20:20:40 +0000243 George V. Reilly Win32 port, Win32 GUI start-off
244 Stephen Riehm bug collector
245 Stefan Roemer various patches and help to users
246 Ralf Schandl IBM OS/390 port
247 Olaf Seibert DICE and BeBox version, regexp improvements
248 Mortaza Shiran Farsi patches
249 Peter da Silva termlib
250 Paul Slootman OS/2 port
251 Henry Spencer regular expressions
252 Dany St-Amant Macintosh port
253 Tim Thompson Stevie
254 G. R. (Fred) Walter Stevie
255 Sven Verdoolaege Perl interface
256 Robert Webb Command-line completion, GUI versions, and
257 lots of patches
258 Ingo Wilken Tcl interface
259 Mike Williams PostScript printing
260 Juergen Weigert Lattice version, AUX improvements, UNIX and
261 MS-DOS ports, autoconf
262 Stefan 'Sec' Zehl Maintainer of vim.org
Bram Moolenaar37c64c72017-09-19 22:06:03 +0200263 Yasuhiro Matsumoto many MS-Windows improvements
264 Ken Takata fixes and features
265 Kazunobu Kuriyama GTK 3
266 Christian Brabandt many fixes, features, user support, etc.
Bram Moolenaar4c05fa02019-01-01 15:32:17 +0100267 Yegappan Lakshmanan many quickfix features
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268
269I wish to thank all the people that sent me bug reports and suggestions. The
270list is too long to mention them all here. Vim would not be the same without
271the ideas from all these people: They keep Vim alive!
Bram Moolenaar56b45b92013-06-24 22:22:18 +0200272*love* *peace* *friendship* *gross-national-happiness*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273
274
275In this documentation there are several references to other versions of Vi:
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000276 *Vi* *vi*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000277Vi "the original". Without further remarks this is the version
278 of Vi that appeared in Sun OS 4.x. ":version" returns
279 "Version 3.7, 6/7/85". Sometimes other versions are referred
Bram Moolenaard09091d2019-01-17 16:07:22 +0100280 to. Only runs under Unix. Source code is now available under a
281 BSD-style license. More information on Vi can be found through:
282 http://ex-vi.sourceforge.net/
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283 *Posix*
284Posix From the IEEE standard 1003.2, Part 2: Shell and utilities.
285 Generally known as "Posix". This is a textual description of
286 how Vi is supposed to work.
Bram Moolenaar7c626922005-02-07 22:01:03 +0000287 See |posix-compliance|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288 *Nvi*
289Nvi The "New" Vi. The version of Vi that comes with BSD 4.4 and FreeBSD.
290 Very good compatibility with the original Vi, with a few extensions.
291 The version used is 1.79. ":version" returns "Version 1.79
292 (10/23/96)". There has been no release the last few years, although
293 there is a development version 1.81.
294 Source code is freely available.
295 *Elvis*
296Elvis Another Vi clone, made by Steve Kirkendall. Very compact but isn't
Bram Moolenaard09091d2019-01-17 16:07:22 +0100297 as flexible as Vim. Development has stalled, Elvis has left the
298 building! Source code is freely available.
299 *Neovim*
300Neovim A Vim clone. Forked the Vim source in 2014 and went a different way.
Bram Moolenaar4c05fa02019-01-01 15:32:17 +0100301 Very much bound to github and has many more dependencies, making
302 development more complex and limiting portability. Code has been
303 refactored, resulting in patches not being exchangeable with Vim.
304 Supports a remote GUI and integration with scripting languages.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305
306==============================================================================
3074. Notation *notation*
308
309When syntax highlighting is used to read this, text that is not typed
310literally is often highlighted with the Special group. These are items in [],
311{} and <>, and CTRL-X.
312
313Note that Vim uses all possible characters in commands. Sometimes the [], {}
314and <> are part of what you type, the context should make this clear.
315
316
317[] Characters in square brackets are optional.
318
Bram Moolenaar4a748032010-09-30 21:47:56 +0200319 *count* *[count]*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320[count] An optional number that may precede the command to multiply
321 or iterate the command. If no number is given, a count of one
322 is used, unless otherwise noted. Note that in this manual the
323 [count] is not mentioned in the description of the command,
324 but only in the explanation. This was done to make the
325 commands easier to look up. If the 'showcmd' option is on,
326 the (partially) entered count is shown at the bottom of the
327 window. You can use <Del> to erase the last digit (|N<Del>|).
328
329 *[quotex]*
330["x] An optional register designation where text can be stored.
331 See |registers|. The x is a single character between 'a' and
332 'z' or 'A' and 'Z' or '"', and in some cases (with the put
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000333 command) between '0' and '9', '%', '#', or others. The
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334 uppercase and lowercase letter designate the same register,
335 but the lowercase letter is used to overwrite the previous
336 register contents, while the uppercase letter is used to
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000337 append to the previous register contents. Without the ""x" or
Bram Moolenaar071d4272004-06-13 20:20:40 +0000338 with """" the stored text is put into the unnamed register.
339
340 *{}*
341{} Curly braces denote parts of the command which must appear,
342 but which can take a number of different values. The
343 differences between Vim and Vi are also given in curly braces
344 (this will be clear from the context).
345
346 *{char1-char2}*
347{char1-char2} A single character from the range char1 to char2. For
348 example: {a-z} is a lowercase letter. Multiple ranges may be
349 concatenated. For example, {a-zA-Z0-9} is any alphanumeric
350 character.
351
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000352 *{motion}* *movement*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353{motion} A command that moves the cursor. These are explained in
354 |motion.txt|. Examples:
355 w to start of next word
356 b to begin of current word
357 4j four lines down
358 /The<CR> to next occurrence of "The"
359 This is used after an |operator| command to move over the text
360 that is to be operated upon.
361 - If the motion includes a count and the operator also has a
362 count, the two counts are multiplied. For example: "2d3w"
363 deletes six words.
364 - The motion can be backwards, e.g. "db" to delete to the
365 start of the word.
366 - The motion can also be a mouse click. The mouse is not
367 supported in every terminal though.
368 - The ":omap" command can be used to map characters while an
369 operator is pending.
370 - Ex commands can be used to move the cursor. This can be
371 used to call a function that does some complicated motion.
372 The motion is always characterwise exclusive, no matter
373 what ":" command is used. This means it's impossible to
374 include the last character of a line without the line break
375 (unless 'virtualedit' is set).
376 If the Ex command changes the text before where the operator
377 starts or jumps to another buffer the result is
378 unpredictable. It is possible to change the text further
379 down. Jumping to another buffer is possible if the current
380 buffer is not unloaded.
381
382 *{Visual}*
383{Visual} A selected text area. It is started with the "v", "V", or
384 CTRL-V command, then any cursor movement command can be used
385 to change the end of the selected text.
386 This is used before an |operator| command to highlight the
387 text that is to be operated upon.
388 See |Visual-mode|.
389
390 *<character>*
391<character> A special character from the table below, optionally with
392 modifiers, or a single ASCII character with modifiers.
393
394 *'character'*
395'c' A single ASCII character.
396
397 *CTRL-{char}*
398CTRL-{char} {char} typed as a control character; that is, typing {char}
399 while holding the CTRL key down. The case of {char} does not
400 matter; thus CTRL-A and CTRL-a are equivalent. But on some
401 terminals, using the SHIFT key will produce another code,
402 don't use it then.
403
404 *'option'*
405'option' An option, or parameter, that can be set to a value, is
406 enclosed in single quotes. See |options|.
407
408 *quotecommandquote*
409"command" A reference to a command that you can type is enclosed in
410 double quotes.
Bram Moolenaar00154502013-02-13 16:15:55 +0100411`command` New style command, this distinguishes it from other quoted
412 text and strings.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413
414 *key-notation* *key-codes* *keycodes*
415These names for keys are used in the documentation. They can also be used
416with the ":map" command (insert the key name by pressing CTRL-K and then the
417key you want the name for).
418
419notation meaning equivalent decimal value(s) ~
420-----------------------------------------------------------------------
421<Nul> zero CTRL-@ 0 (stored as 10) *<Nul>*
422<BS> backspace CTRL-H 8 *backspace*
423<Tab> tab CTRL-I 9 *tab* *Tab*
424 *linefeed*
425<NL> linefeed CTRL-J 10 (used for <Nul>)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426<CR> carriage return CTRL-M 13 *carriage-return*
427<Return> same as <CR> *<Return>*
428<Enter> same as <CR> *<Enter>*
429<Esc> escape CTRL-[ 27 *escape* *<Esc>*
430<Space> space 32 *space*
431<lt> less-than < 60 *<lt>*
432<Bslash> backslash \ 92 *backslash* *<Bslash>*
433<Bar> vertical bar | 124 *<Bar>*
434<Del> delete 127
435<CSI> command sequence intro ALT-Esc 155 *<CSI>*
436<xCSI> CSI when typed in the GUI *<xCSI>*
437
Bram Moolenaar4072ba52020-12-23 13:56:35 +0100438<EOL> end-of-line (can be <CR>, <NL> or <CR><NL>,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000439 depends on system and 'fileformat') *<EOL>*
440
441<Up> cursor-up *cursor-up* *cursor_up*
442<Down> cursor-down *cursor-down* *cursor_down*
443<Left> cursor-left *cursor-left* *cursor_left*
444<Right> cursor-right *cursor-right* *cursor_right*
445<S-Up> shift-cursor-up
446<S-Down> shift-cursor-down
447<S-Left> shift-cursor-left
448<S-Right> shift-cursor-right
449<C-Left> control-cursor-left
450<C-Right> control-cursor-right
451<F1> - <F12> function keys 1 to 12 *function_key* *function-key*
452<S-F1> - <S-F12> shift-function keys 1 to 12 *<S-F1>*
453<Help> help key
454<Undo> undo key
455<Insert> insert key
456<Home> home *home*
457<End> end *end*
458<PageUp> page-up *page_up* *page-up*
459<PageDown> page-down *page_down* *page-down*
460<kHome> keypad home (upper left) *keypad-home*
461<kEnd> keypad end (lower left) *keypad-end*
462<kPageUp> keypad page-up (upper right) *keypad-page-up*
463<kPageDown> keypad page-down (lower right) *keypad-page-down*
464<kPlus> keypad + *keypad-plus*
465<kMinus> keypad - *keypad-minus*
466<kMultiply> keypad * *keypad-multiply*
467<kDivide> keypad / *keypad-divide*
468<kEnter> keypad Enter *keypad-enter*
469<kPoint> keypad Decimal point *keypad-point*
470<k0> - <k9> keypad 0 to 9 *keypad-0* *keypad-9*
471<S-...> shift-key *shift* *<S-*
472<C-...> control-key *control* *ctrl* *<C-*
473<M-...> alt-key or meta-key *meta* *alt* *<M-*
474<A-...> same as <M-...> *<A-*
475<D-...> command-key (Macintosh only) *<D-*
476<t_xx> key with "xx" entry in termcap
477-----------------------------------------------------------------------
478
479Note: The shifted cursor keys, the help key, and the undo key are only
480available on a few terminals. On the Amiga, shifted function key 10 produces
481a code (CSI) that is also used by key sequences. It will be recognized only
482after typing another key.
483
484Note: There are two codes for the delete key. 127 is the decimal ASCII value
485for the delete key, which is always recognized. Some delete keys send another
486value, in which case this value is obtained from the termcap entry "kD". Both
487values have the same effect. Also see |:fixdel|.
488
489Note: The keypad keys are used in the same way as the corresponding "normal"
490keys. For example, <kHome> has the same effect as <Home>. If a keypad key
491sends the same raw key code as its non-keypad equivalent, it will be
492recognized as the non-keypad code. For example, when <kHome> sends the same
493code as <Home>, when pressing <kHome> Vim will think <Home> was pressed.
494Mapping <kHome> will not work then.
495
496 *<>*
497Examples are often given in the <> notation. Sometimes this is just to make
498clear what you need to type, but often it can be typed literally, e.g., with
499the ":map" command. The rules are:
500 1. Any printable characters are typed directly, except backslash and '<'
501 2. A backslash is represented with "\\", double backslash, or "<Bslash>".
502 3. A real '<' is represented with "\<" or "<lt>". When there is no
503 confusion possible, a '<' can be used directly.
504 4. "<key>" means the special key typed. This is the notation explained in
505 the table above. A few examples:
506 <Esc> Escape key
507 <C-G> CTRL-G
508 <Up> cursor up key
509 <C-LeftMouse> Control- left mouse click
510 <S-F11> Shifted function key 11
511 <M-a> Meta- a ('a' with bit 8 set)
512 <M-A> Meta- A ('A' with bit 8 set)
513 <t_kd> "kd" termcap entry (cursor down key)
Bram Moolenaar207f0092020-08-30 17:20:20 +0200514 Although you can specify <M-{char}> with {char} being a multibyte
Bram Moolenaar56c860c2019-08-17 20:09:31 +0200515 character, Vim may not be able to know what byte sequence that is and then
516 it won't work.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000517
518If you want to use the full <> notation in Vim, you have to make sure the '<'
519flag is excluded from 'cpoptions' (when 'compatible' is not set, it already is
520by default). >
521 :set cpo-=<
522The <> notation uses <lt> to escape the special meaning of key names. Using a
523backslash also works, but only when 'cpoptions' does not include the 'B' flag.
524
525Examples for mapping CTRL-H to the six characters "<Home>": >
526 :imap <C-H> \<Home>
527 :imap <C-H> <lt>Home>
528The first one only works when the 'B' flag is not in 'cpoptions'. The second
529one always works.
530To get a literal "<lt>" in a mapping: >
531 :map <C-L> <lt>lt>
532
533For mapping, abbreviation and menu commands you can then copy-paste the
534examples and use them directly. Or type them literally, including the '<' and
535'>' characters. This does NOT work for other commands, like ":set" and
536":autocmd"!
537
Bram Moolenaar9712ff12022-09-18 13:04:22 +0100538The notation can be used in a double quoted strings, using "\<" at the start,
539e.g. "\<C-Space>". This results in a special key code. To convert this back
540to readable text use `keytrans()`.
541
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542==============================================================================
5435. Modes, introduction *vim-modes-intro* *vim-modes*
544
Bram Moolenaar1ccd8ff2017-08-11 19:50:37 +0200545Vim has seven BASIC modes:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546
547 *Normal* *Normal-mode* *command-mode*
548Normal mode In Normal mode you can enter all the normal editor
549 commands. If you start the editor you are in this
550 mode (unless you have set the 'insertmode' option,
551 see below). This is also known as command mode.
552
553Visual mode This is like Normal mode, but the movement commands
554 extend a highlighted area. When a non-movement
555 command is used, it is executed for the highlighted
556 area. See |Visual-mode|.
557 If the 'showmode' option is on "-- VISUAL --" is shown
558 at the bottom of the window.
559
560Select mode This looks most like the MS-Windows selection mode.
561 Typing a printable character deletes the selection
562 and starts Insert mode. See |Select-mode|.
563 If the 'showmode' option is on "-- SELECT --" is shown
564 at the bottom of the window.
565
566Insert mode In Insert mode the text you type is inserted into the
567 buffer. See |Insert-mode|.
568 If the 'showmode' option is on "-- INSERT --" is shown
569 at the bottom of the window.
570
571Command-line mode In Command-line mode (also called Cmdline mode) you
572Cmdline mode can enter one line of text at the bottom of the
573 window. This is for the Ex commands, ":", the pattern
574 search commands, "?" and "/", and the filter command,
575 "!". |Cmdline-mode|
576
577Ex mode Like Command-line mode, but after entering a command
578 you remain in Ex mode. Very limited editing of the
579 command line. |Ex-mode|
580
Bram Moolenaar1ccd8ff2017-08-11 19:50:37 +0200581Terminal-Job mode Interacting with a job in a terminal window. Typed
582 keys go to the job and the job output is displayed in
583 the terminal window. See |terminal| about how to
584 switch to other modes.
585
Bram Moolenaarf55e4c82017-08-01 20:44:53 +0200586There are seven ADDITIONAL modes. These are variants of the BASIC modes:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587
588 *Operator-pending* *Operator-pending-mode*
589Operator-pending mode This is like Normal mode, but after an operator
590 command has started, and Vim is waiting for a {motion}
591 to specify the text that the operator will work on.
592
593Replace mode Replace mode is a special case of Insert mode. You
594 can do the same things as in Insert mode, but for
595 each character you enter, one character of the existing
596 text is deleted. See |Replace-mode|.
597 If the 'showmode' option is on "-- REPLACE --" is
598 shown at the bottom of the window.
599
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000600Virtual Replace mode Virtual Replace mode is similar to Replace mode, but
601 instead of file characters you are replacing screen
602 real estate. See |Virtual-Replace-mode|.
603 If the 'showmode' option is on "-- VREPLACE --" is
604 shown at the bottom of the window.
605
Bram Moolenaard473c8c2018-08-11 18:00:22 +0200606Insert Normal mode Entered when CTRL-O is typed in Insert mode (see
607 |i_CTRL-O|). This is like Normal mode, but after
608 executing one command Vim returns to Insert mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609 If the 'showmode' option is on "-- (insert) --" is
610 shown at the bottom of the window.
611
Bram Moolenaar1ccd8ff2017-08-11 19:50:37 +0200612Terminal-Normal mode Using Normal mode in a terminal window. Making
613 changes is impossible. Use an insert command, such as
614 "a" or "i", to return to Terminal-Job mode.
Bram Moolenaarf55e4c82017-08-01 20:44:53 +0200615
Bram Moolenaar071d4272004-06-13 20:20:40 +0000616Insert Visual mode Entered when starting a Visual selection from Insert
617 mode, e.g., by using CTRL-O and then "v", "V" or
618 CTRL-V. When the Visual selection ends, Vim returns
619 to Insert mode.
620 If the 'showmode' option is on "-- (insert) VISUAL --"
621 is shown at the bottom of the window.
622
623Insert Select mode Entered when starting Select mode from Insert mode.
624 E.g., by dragging the mouse or <S-Right>.
625 When the Select mode ends, Vim returns to Insert mode.
626 If the 'showmode' option is on "-- (insert) SELECT --"
627 is shown at the bottom of the window.
628
629==============================================================================
6306. Switching from mode to mode *mode-switching*
631
632If for any reason you do not know which mode you are in, you can always get
633back to Normal mode by typing <Esc> twice. This doesn't work for Ex mode
634though, use ":visual".
635You will know you are back in Normal mode when you see the screen flash or
636hear the bell after you type <Esc>. However, when pressing <Esc> after using
637CTRL-O in Insert mode you get a beep but you are still in Insert mode, type
638<Esc> again.
639
640 *i_esc*
641 TO mode ~
642 Normal Visual Select Insert Replace Cmd-line Ex ~
643FROM mode ~
Bram Moolenaar8c8de832008-06-24 22:58:06 +0000644Normal v V ^V *4 *1 R gR : / ? ! Q
Bram Moolenaar071d4272004-06-13 20:20:40 +0000645Visual *2 ^G c C -- : --
646Select *5 ^O ^G *6 -- -- --
647Insert <Esc> -- -- <Insert> -- --
648Replace <Esc> -- -- <Insert> -- --
649Command-line *3 -- -- :start -- --
650Ex :vi -- -- -- -- --
651
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652-- not possible
653
654*1 Go from Normal mode to Insert mode by giving the command "i", "I", "a",
655 "A", "o", "O", "c", "C", "s" or S".
656*2 Go from Visual mode to Normal mode by giving a non-movement command, which
657 causes the command to be executed, or by hitting <Esc> "v", "V" or "CTRL-V"
658 (see |v_v|), which just stops Visual mode without side effects.
659*3 Go from Command-line mode to Normal mode by:
660 - Hitting <CR> or <NL>, which causes the entered command to be executed.
661 - Deleting the complete line (e.g., with CTRL-U) and giving a final <BS>.
662 - Hitting CTRL-C or <Esc>, which quits the command-line without executing
663 the command.
664 In the last case <Esc> may be the character defined with the 'wildchar'
665 option, in which case it will start command-line completion. You can
Bram Moolenaara6c27c42019-05-09 19:16:22 +0200666 ignore that and type <Esc> again.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667*4 Go from Normal to Select mode by:
668 - use the mouse to select text while 'selectmode' contains "mouse"
669 - use a non-printable command to move the cursor while keeping the Shift
670 key pressed, and the 'selectmode' option contains "key"
671 - use "v", "V" or "CTRL-V" while 'selectmode' contains "cmd"
672 - use "gh", "gH" or "g CTRL-H" |g_CTRL-H|
673*5 Go from Select mode to Normal mode by using a non-printable command to move
674 the cursor, without keeping the Shift key pressed.
675*6 Go from Select mode to Insert mode by typing a printable character. The
676 selection is deleted and the character is inserted.
677
678If the 'insertmode' option is on, editing a file will start in Insert mode.
679
680 *CTRL-\_CTRL-N* *i_CTRL-\_CTRL-N* *c_CTRL-\_CTRL-N* *v_CTRL-\_CTRL-N*
681Additionally the command CTRL-\ CTRL-N or <C-\><C-N> can be used to go to
682Normal mode from any other mode. This can be used to make sure Vim is in
683Normal mode, without causing a beep like <Esc> would. However, this does not
684work in Ex mode. When used after a command that takes an argument, such as
685|f| or |m|, the timeout set with 'ttimeoutlen' applies.
Bram Moolenaar7e6a5152021-01-02 16:39:53 +0100686When focus is in a terminal window, CTRL-\ CTRL-N goes to Normal mode until an
687edit command is entered, see |t_CTRL-\_CTRL-N|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000688
689 *CTRL-\_CTRL-G* *i_CTRL-\_CTRL-G* *c_CTRL-\_CTRL-G* *v_CTRL-\_CTRL-G*
690The command CTRL-\ CTRL-G or <C-\><C-G> can be used to go to Insert mode when
691'insertmode' is set. Otherwise it goes to Normal mode. This can be used to
692make sure Vim is in the mode indicated by 'insertmode', without knowing in
693what mode Vim currently is.
694
695 *Q* *mode-Ex* *Ex-mode* *Ex* *EX* *E501*
696Q Switch to "Ex" mode. This is a bit like typing ":"
697 commands one after another, except:
698 - You don't have to keep pressing ":".
699 - The screen doesn't get updated after each command.
700 - There is no normal command-line editing.
701 - Mappings and abbreviations are not used.
702 In fact, you are editing the lines with the "standard"
703 line-input editing commands (<Del> or <BS> to erase,
704 CTRL-U to kill the whole line).
705 Vim will enter this mode by default if it's invoked as
Bram Moolenaar5ed11532022-07-06 13:18:11 +0100706 "ex" on the command-line or the |-e| command line
707 argument was used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 Use the ":vi" command |:visual| to exit "Ex" mode.
709 Note: In older versions of Vim "Q" formatted text,
710 that is now done with |gq|. But if you use the
Bram Moolenaar1588bc82022-03-08 21:35:07 +0000711 |vimrc_example.vim| script or |defaults.vim|, "Q"
712 works like "gq". Except for Select mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713
714 *gQ*
Bram Moolenaar7c626922005-02-07 22:01:03 +0000715gQ Switch to "Ex" mode like with "Q", but really behave
716 like typing ":" commands after another. All command
717 line editing, completion etc. is available.
Bram Moolenaar5ed11532022-07-06 13:18:11 +0100718 Use the `:vi` command (`:visual`) to exit "Ex" mode.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719
720==============================================================================
7217. The window contents *window-contents*
722
723In Normal mode and Insert/Replace mode the screen window will show the current
724contents of the buffer: What You See Is What You Get. There are two
725exceptions:
726- When the 'cpoptions' option contains '$', and the change is within one line,
727 the text is not directly deleted, but a '$' is put at the last deleted
728 character.
729- When inserting text in one window, other windows on the same text are not
730 updated until the insert is finished.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731
732Lines longer than the window width will wrap, unless the 'wrap' option is off
733(see below). The 'linebreak' option can be set to wrap at a blank character.
734
735If the window has room after the last line of the buffer, Vim will show '~' in
Bram Moolenaar166af9b2010-11-16 20:34:40 +0100736the first column of the last lines in the window, like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000737
738 +-----------------------+
739 |some line |
740 |last line |
741 |~ |
742 |~ |
743 +-----------------------+
744
745Thus the '~' lines indicate that the end of the buffer was reached.
746
747If the last line in a window doesn't fit, Vim will indicate this with a '@' in
Bram Moolenaar166af9b2010-11-16 20:34:40 +0100748the first column of the last lines in the window, like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749
750 +-----------------------+
751 |first line |
752 |second line |
753 |@ |
754 |@ |
755 +-----------------------+
756
757Thus the '@' lines indicate that there is a line that doesn't fit in the
758window.
759
760When the "lastline" flag is present in the 'display' option, you will not see
761'@' characters at the left side of window. If the last line doesn't fit
762completely, only the part that fits is shown, and the last three characters of
Bram Moolenaar81af9252010-12-10 20:35:50 +0100763the last line are replaced with "@@@", like this:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764
765 +-----------------------+
766 |first line |
767 |second line |
768 |a very long line that d|
769 |oesn't fit in the wi@@@|
770 +-----------------------+
771
772If there is a single line that is too long to fit in the window, this is a
773special situation. Vim will show only part of the line, around where the
774cursor is. There are no special characters shown, so that you can edit all
775parts of this line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776
777The '@' occasion in the 'highlight' option can be used to set special
778highlighting for the '@' and '~' characters. This makes it possible to
779distinguish them from real characters in the buffer.
780
781The 'showbreak' option contains the string to put in front of wrapped lines.
782
783 *wrap-off*
784If the 'wrap' option is off, long lines will not wrap. Only the part that
785fits on the screen is shown. If the cursor is moved to a part of the line
786that is not shown, the screen is scrolled horizontally. The advantage of
787this method is that columns are shown as they are and lines that cannot fit
788on the screen can be edited. The disadvantage is that you cannot see all the
789characters of a line at once. The 'sidescroll' option can be set to the
Bram Moolenaara6c27c42019-05-09 19:16:22 +0200790minimal number of columns to scroll.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791
792All normal ASCII characters are displayed directly on the screen. The <Tab>
793is replaced with the number of spaces that it represents. Other non-printing
794characters are replaced with "^{char}", where {char} is the non-printing
795character with 64 added. Thus character 7 (bell) will be shown as "^G".
796Characters between 127 and 160 are replaced with "~{char}", where {char} is
797the character with 64 subtracted. These characters occupy more than one
798position on the screen. The cursor can only be positioned on the first one.
799
800If you set the 'number' option, all lines will be preceded with their
801number. Tip: If you don't like wrapping lines to mix with the line numbers,
802set the 'showbreak' option to eight spaces:
803 ":set showbreak=\ \ \ \ \ \ \ \ "
804
805If you set the 'list' option, <Tab> characters will not be shown as several
806spaces, but as "^I". A '$' will be placed at the end of the line, so you can
807find trailing blanks.
808
809In Command-line mode only the command-line itself is shown correctly. The
810display of the buffer contents is updated as soon as you go back to Command
811mode.
812
813The last line of the window is used for status and other messages. The
814status messages will only be used if an option is on:
815
816status message option default Unix default ~
817current mode 'showmode' on on
818command characters 'showcmd' on off
819cursor position 'ruler' off off
820
821The current mode is "-- INSERT --" or "-- REPLACE --", see |'showmode'|. The
Bram Moolenaara6c27c42019-05-09 19:16:22 +0200822command characters are those that you typed but were not used yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823
824If you have a slow terminal you can switch off the status messages to speed
825up editing:
826 :set nosc noru nosm
827
828If there is an error, an error message will be shown for at least one second
Bram Moolenaara6c27c42019-05-09 19:16:22 +0200829(in reverse video).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830
831Some commands show how many lines were affected. Above which threshold this
832happens can be controlled with the 'report' option (default 2).
833
834On the Amiga Vim will run in a CLI window. The name Vim and the full name of
835the current file name will be shown in the title bar. When the window is
836resized, Vim will automatically redraw the window. You may make the window as
837small as you like, but if it gets too small not a single line will fit in it.
838Make it at least 40 characters wide to be able to read most messages on the
839last line.
840
841On most Unix systems, resizing the window is recognized and handled correctly
Bram Moolenaara6c27c42019-05-09 19:16:22 +0200842by Vim.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843
844==============================================================================
8458. Definitions *definitions*
846
Bram Moolenaarc572da52017-08-27 16:52:01 +0200847 buffer Contains lines of text, usually read from a file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848 screen The whole area that Vim uses to work in. This can be
849 a terminal emulator window. Also called "the Vim
850 window".
Bram Moolenaarc572da52017-08-27 16:52:01 +0200851 window A view on a buffer. There can be multiple windows for
852 one buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000853
854A screen contains one or more windows, separated by status lines and with the
855command line at the bottom.
856
857 +-------------------------------+
858screen | window 1 | window 2 |
859 | | |
860 | | |
861 |= status line =|= status line =|
862 | window 3 |
863 | |
864 | |
865 |==== status line ==============|
866 |command line |
867 +-------------------------------+
868
869The command line is also used for messages. It scrolls up the screen when
870there is not enough room in the command line.
871
872A difference is made between four types of lines:
873
874 buffer lines The lines in the buffer. This is the same as the
875 lines as they are read from/written to a file. They
876 can be thousands of characters long.
877 logical lines The buffer lines with folding applied. Buffer lines
878 in a closed fold are changed to a single logical line:
879 "+-- 99 lines folded". They can be thousands of
880 characters long.
881 window lines The lines displayed in a window: A range of logical
882 lines with wrapping, line breaks, etc. applied. They
883 can only be as long as the width of the window allows,
884 longer lines are wrapped or truncated.
885 screen lines The lines of the screen that Vim uses. Consists of
886 the window lines of all windows, with status lines
887 and the command line added. They can only be as long
888 as the width of the screen allows. When the command
889 line gets longer it wraps and lines are scrolled to
890 make room.
891
892buffer lines logical lines window lines screen lines ~
893
8941. one 1. one 1. +-- folded 1. +-- folded
8952. two 2. +-- folded 2. five 2. five
8963. three 3. five 3. six 3. six
8974. four 4. six 4. seven 4. seven
8985. five 5. seven 5. === status line ===
8996. six 6. aaa
9007. seven 7. bbb
901 8. ccc ccc c
9021. aaa 1. aaa 1. aaa 9. cc
9032. bbb 2. bbb 2. bbb 10. ddd
9043. ccc ccc ccc 3. ccc ccc ccc 3. ccc ccc c 11. ~
9054. ddd 4. ddd 4. cc 12. === status line ===
906 5. ddd 13. (command line)
907 6. ~
908
909==============================================================================
Bram Moolenaar91f84f62018-07-29 15:07:52 +0200910 vim:tw=78:ts=8:noet:ft=help:norl: