1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
|
*insert.txt* For Vim version 7.0aa. Last change: 2004 Jun 24
VIM REFERENCE MANUAL by Bram Moolenaar
*Insert* *Insert-mode*
Inserting and replacing text *mode-ins-repl*
Most of this file is about Insert and Replace mode. At the end are a few
commands for inserting text in other ways.
An overview of the most often used commands can be found in chapter 24 of the
user manual |usr_24.txt|.
1. Special keys |ins-special-keys|
2. Special special keys |ins-special-special|
3. 'textwidth' and 'wrapmargin' options |ins-textwidth|
4. 'expandtab', 'smarttab' and 'softtabstop' options |ins-expandtab|
5. Replace mode |Replace-mode|
6. Virtual Replace mode |Virtual-Replace-mode|
7. Insert mode completion |ins-completion|
8. Insert mode commands |inserting|
9. Ex insert commands |inserting-ex|
10. Inserting a file |inserting-file|
Also see 'virtualedit', for moving the cursor to positions where there is no
character. Useful for editing a table.
==============================================================================
1. Special keys *ins-special-keys*
In Insert and Replace mode, the following characters have a special meaning;
other characters are inserted directly. To insert one of these special
characters into the buffer, precede it with CTRL-V. To insert a <Nul>
character use "CTRL-V CTRL-@" or "CTRL-V 000". On some systems, you have to
use "CTRL-V 003" to insert a CTRL-C. Note: When CTRL-V is mapped you can
often use CTRL-Q instead |i_CTRL-Q|.
If you are working in a special language mode when inserting text, see the
'langmap' option, |'langmap'|, on how to avoid switching this mode on and off
all the time.
If you have 'insertmode' set, <Esc> and a few other keys get another meaning.
See |'insertmode'|.
char action ~
-----------------------------------------------------------------------
*i_CTRL-[* *i_<Esc>*
<Esc> or CTRL-[ End insert or Replace mode, go back to Normal mode. Finish
abbreviation.
Note: If your <Esc> key is hard to hit on your keyboard, train
yourself to use CTRL-[.
*i_CTRL-C*
CTRL-C Quit insert mode, go back to Normal mode. Do not check for
abbreviations.
*i_CTRL-@*
CTRL-@ Insert previously inserted text and stop insert. {Vi: only
when typed as first char, only up to 128 chars}
*i_CTRL-A*
CTRL-A Insert previously inserted text. {not in Vi}
*i_CTRL-H* *i_<BS>* *i_BS*
<BS> or CTRL-H Delete the character before the cursor (see |i_backspacing|
about joining lines).
See |:fixdel| if your <BS> key does not do what you want.
{Vi: does not delete autoindents}
*i_<Del>* *i_DEL*
<Del> Delete the character under the cursor. If the cursor is at
the end of the line, and the 'backspace' option includes
"eol", delete the <EOL>; the next line is appended after the
current one.
See |:fixdel| if your <Del> key does not do what you want.
{not in Vi}
*i_CTRL-W*
CTRL-W Delete the word before the cursor (see |i_backspacing| about
joining lines). See the section "word motions",
|word-motions|, for the definition of a word.
*i_CTRL-U*
CTRL-U Delete all entered characters in the current line (see
|i_backspacing| about joining lines).
*i_CTRL-I* *i_<Tab>* *i_Tab*
<Tab> or CTRL-I Insert a tab. If the 'expandtab' option is on, the
equivalent number of spaces is inserted (use CTRL-V <Tab> to
avoid the expansion; use CTRL-Q <Tab> if CTRL-V is mapped
|i_CTRL-Q|). See also the 'smarttab' option and
|ins-expandtab|.
*i_CTRL-J* *i_<NL>*
<NL> or CTRL-J Begin new line.
*i_CTRL-M* *i_<CR>*
<CR> or CTRL-M Begin new line.
*i_CTRL-K*
CTRL-K {char1} [char2]
Enter digraph (see |digraphs|). When {char1} is a special
key, the code for that key is inserted in <> form. For
example, the string "<S-Space>" can be entered by typing
<C-K><S-Space> (two keys). Neither char is considered for
mapping. {not in Vi}
CTRL-N Find next keyword (see |i_CTRL-N|). {not in Vi}
CTRL-P Find previous keyword (see |i_CTRL-P|). {not in Vi}
CTRL-R {0-9a-z"%#*+:.-=} *i_CTRL-R*
Insert the contents of a register. Between typing CTRL-R and
the second character, '"' will be displayed to indicate that
you are expected to enter the name of a register.
The text is inserted as if you typed it, but mappings and
abbreviations are not used. If you have options like
'textwidth', 'formatoptions', or 'autoindent' set, this will
influence what will be inserted. This is different from what
happens with the "p" command and pasting with the mouse.
Special registers:
'"' the unnamed register, containing the text of
the last delete or yank
'%' the current file name
'#' the alternate file name
'*' the clipboard contents (X11: primary selection)
'+' the clipboard contents
'/' the last search pattern
':' the last command-line
'.' the last inserted text
'-' the last small (less than a line) delete
'=' the expression register: you are prompted to
enter an expression (see |expression|)
See |registers| about registers. {not in Vi}
CTRL-R CTRL-R {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-R*
Insert the contents of a register. Works like using a single
CTRL-R, but the text is inserted literally, not as if typed.
This differs when the register contains characters like <BS>.
Example, where register a contains "ab^Hc": >
CTRL-R a results in "ac".
CTRL-R CTRL-R a results in "ab^Hc".
< Options 'textwidth', 'formatoptions', etc. still apply. If
you also want to avoid these, use "<C-R><C-O>r", see below.
The '.' register (last inserted text) is still inserted as
typed. {not in Vi}
CTRL-R CTRL-O {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-O*
Insert the contents of a register literally and don't
auto-indent. Does the same as pasting with the mouse
|<MiddleMouse>|.
Does not replace characters!
The '.' register (last inserted text) is still inserted as
typed. {not in Vi}
CTRL-R CTRL-P {0-9a-z"%#*+/:.-=} *i_CTRL-R_CTRL-P*
Insert the contents of a register literally and fix the
indent, like |[<MiddleMouse>|.
Does not replace characters!
The '.' register (last inserted text) is still inserted as
typed. {not in Vi}
*i_CTRL-T*
CTRL-T Insert one shiftwidth of indent at the start of the current
line. The indent is always rounded to a 'shiftwidth' (this is
vi compatible). {Vi: only when in indent}
*i_CTRL-D*
CTRL-D Delete one shiftwidth of indent at the start of the current
line. The indent is always rounded to a 'shiftwidth' (this is
vi compatible). {Vi: CTRL-D works only when used after
autoindent}
*i_0_CTRL-D*
0 CTRL-D Delete all indent in the current line. {Vi: CTRL-D works
only when used after autoindent}
*i_^_CTRL-D*
^ CTRL-D Delete all indent in the current line. The indent is
restored in the next line. This is useful when inserting a
label. {Vi: CTRL-D works only when used after autoindent}
*i_CTRL-V*
CTRL-V Insert next non-digit literally. For special keys, the
terminal code is inserted. It's also possible to enter the
decimal, octal or hexadecimal value of a character
|i_CTRL-V_digit|.
The characters typed right after CTRL-V are not considered for
mapping. {Vi: no decimal byte entry}
Note: When CTRL-V is mapped (e.g., to paste text) you can
often use CTRL-Q instead |i_CTRL-Q|.
*i_CTRL-Q*
CTRL-Q Same as CTRL-V.
Note: Some terminal connections may eat CTRL-Q, it doesn't
work then. It does work in the GUI.
CTRL-X Enter CTRL-X mode. This is a sub-mode where commands can
be given to complete words or scroll the window. See
|i_CTRL-X| and |ins-completion|. {not in Vi}
*i_CTRL-E*
CTRL-E Insert the character which is below the cursor. {not in Vi}
*i_CTRL-Y*
CTRL-Y Insert the character which is above the cursor. {not in Vi}
Note that for CTRL-E and CTRL-Y 'textwidth' is not used, to be
able to copy characters from a long line.
*i_CTRL-_*
CTRL-_ Switch between languages, as follows:
- When in a rightleft window, revins and nohkmap are toggled,
since English will likely be inserted in this case.
- When in a norightleft window, revins and hkmap are toggled,
since Hebrew will likely be inserted in this case.
CTRL-_ moves the cursor to the end of the typed text.
This command is only available when the 'allowrevins' option
is set.
Please refer to |rileft.txt| for more information about
right-to-left mode.
{not in Vi}
Only if compiled with the |+rightleft| feature (which is not
the default).
*i_CTRL-^*
CTRL-^ Toggle the use of typing language characters.
When language |:lmap| mappings are defined:
- If 'iminsert' is 1 (langmap mappings used) it becomes 0 (no
langmap mappings used).
- If 'iminsert' has another value it becomes 1, thus langmap
mappings are enabled.
When no language mappings are defined:
- If 'iminsert' is 2 (Input Method used) it becomes 0 (no
Input Method used).
- If 'iminsert' has another value it becomes 2, thus the Input
Method is enabled.
When set to 1, the value of the "b:keymap_name" variable, the
'keymap' option or "<lang>" appears in the status line.
The language mappings are normally used to type characters
that are different from what the keyboard produces. The
'keymap' option can be used to install a whole number of them.
{not in Vi}
*i_CTRL-]*
CTRL-] Trigger abbreviation, without inserting a character. {not in
Vi}
*i_<Insert>*
<Insert> Toggle between Insert and Replace mode. {not in Vi}
-----------------------------------------------------------------------
*i_backspacing*
The effect of the <BS>, CTRL-W, and CTRL-U depend on the 'backspace' option
(unless 'revins' is set). This is a comma separated list of items:
item action ~
indent allow backspacing over autoindent
eol allow backspacing over end-of-line (join lines)
start allow backspacing over the start position of insert; CTRL-W and
CTRL-U stop once at the start position
When 'backspace' is empty, Vi compatible backspacing is used. You cannot
backspace over autoindent, before column 1 or before where insert started.
For backwards compatibility the values "0", "1" and "2" are also allowed, see
|'backspace'|.
If the 'backspace' option does contain "eol" and the cursor is in column 1
when one of the three keys is used, the current line is joined with the
previous line. This effectively deletes the <EOL> in front of the cursor.
{Vi: does not cross lines, does not delete past start position of insert}
*i_CTRL-V_digit*
With CTRL-V the decimal, octal or hexadecimal value of a character can be
entered directly. This way you can enter any character, except a line break
(<NL>, value 10). There are five ways to enter the character value:
first char mode max nr of chars max value ~
(none) decimal 3 255
o or O octal 3 255
x or X hexadecimal 2 ff (255)
u hexadecimal 4 ffff (65535)
U hexadecimal 8 7fffffff (2147483647)
Normally you would type the maximum number of characters. Thus to enter a
space (value 32) you would type <C-V>032. You can omit the leading zero, in
which case the character typed after the number must be a non-digit. This
happens for the other modes as well: As soon as you type a character that is
invalid for the mode, the value before it will be used and the "invalid"
character is dealt with in the normal way.
If you enter a value of 10, it will end up in the file as a 0. The 10 is a
<NL>, which is used internally to represent the <Nul> character. When writing
the buffer to a file, the <NL> character is translated into <Nul>. The <NL>
character is written at the end of each line. Thus if you want to insert a
<NL> character in a file you will have to make a line break.
*i_CTRL-X* *insert_expand*
CTRL-X enters a sub-mode where several commands can be used. Most of these
commands do keyword completion; see |ins-completion|. These are not available
when Vim was compiled without the |+insert_expand| feature.
Two commands can be used to scroll the window up or down, without exiting
insert mode:
*i_CTRL-X_CTRL-E*
CTRL-X CTRL-E scroll window one line up.
*i_CTRL-X_CTRL-Y*
CTRL-X CTRL-Y scroll window one line down.
After CTRL-X is pressed, each CTRL-E (CTRL-Y) scrolls the window up (down) by
one line unless that would cause the cursor to move from its current position
in the file. As soon as another key is pressed, CTRL-X mode is exited and
that key is interpreted as in Insert mode.
==============================================================================
2. Special special keys *ins-special-special*
The following keys are special. They stop the current insert, do something,
and then restart insertion. This means you can do something without getting
out of Insert mode. This is very handy if you prefer to use the Insert mode
all the time, just like editors that don't have a separate Normal mode. You
may also want to set the 'backspace' option to "indent,eol,start" and set the
'insertmode' option. You can use CTRL-O if you want to map a function key to
a command.
The changes (inserted or deleted characters) before and after these keys can
be undone separately. Only the last change can be redone and always behaves
like an "i" command.
char action ~
-----------------------------------------------------------------------
<Up> cursor one line up *i_<Up>*
<Down> cursor one line down *i_<Down>*
CTRL-G <Up> cursor one line up, insert start column *i_CTRL-G_<Up>*
CTRL-G k cursor one line up, insert start column *i_CTRL-G_k*
CTRL-G CTRL-K cursor one line up, insert start column *i_CTRL-G_CTRL-K*
CTRL-G <Down> cursor one line down, insert start column *i_CTRL-G_<Down>*
CTRL-G j cursor one line down, insert start column *i_CTRL-G_j*
CTRL-G CTRL-J cursor one line down, insert start column *i_CTRL-G_CTRL-J*
<Left> cursor one character left *i_<Left>*
<Right> cursor one character right *i_<Right>*
<S-Left> cursor one word back (like "b" command) *i_<S-Left>*
<C-Left> cursor one word back (like "b" command) *i_<C-Left>*
<S-Right> cursor one word forward (like "w" command) *i_<S-Right>*
<C-Right> cursor one word forward (like "w" command) *i_<C-Right>*
<Home> cursor to first char in the line *i_<Home>*
<End> cursor to after last char in the line *i_<End>*
<C-Home> cursor to first char in the file *i_<C-Home>*
<C-End> cursor to after last char in the file *i_<C-End>*
<LeftMouse> cursor to position of mouse click *i_<LeftMouse>*
<S-Up> move window one page up *i_<S-Up>*
<PageUp> move window one page up *i_<PageUp>*
<S-Down> move window one page down *i_<S-Down>*
<PageDown> move window one page down *i_<PageDown>*
<MouseDown> scroll three lines down *i_<MouseDown>*
<S-MouseDown> scroll a full page down *i_<S-MouseDown>*
<MouseUp> scroll three lines up *i_<MouseUp>*
<S-MouseUp> scroll a full page up *i_<S-MouseUp>*
CTRL-O execute one command, return to Insert mode *i_CTRL-O*
CTRL-G u break undo sequence, start new change *i_CTRL-G_u*
-----------------------------------------------------------------------
Note: If the cursor keys take you out of Insert mode, check the 'noesckeys'
option.
The CTRL-O command sometimes has a side effect: If the cursor was beyond the
end of the line, it will be put on the last character in the line. In
mappings it's often better to use <Esc> (first put an "x" in the text, <Esc>
will then always put the cursor on it).
The shifted cursor keys are not available on all terminals.
Another side effect is that a count specified before the "i" or "a" command is
ignored. That is because repeating the effect of the command after CTRL-O is
too complicated.
An example for using CTRL-G u: >
:inoremap <C-H> <C-G>u<C-H>
This redefines the backspace key to start a new undo sequence. You can now
undo the effect of the backspace key, without changing what you typed before
that, with CTRL-O u.
Using CTRL-O splits undo: the text typed before and after it is undone
separately. If you want to avoid this (e.g., in a mapping) you might be able
to use CTRL-R = |i_CTRL-R|. E.g., to call a function: >
:imap <F2> <C-R>=MyFunc()<CR>
When the 'whichwrap' option is set appropriately, the <Left> and <Right>
keys on the first/last character in the line make the cursor wrap to the
previous/next line.
The CTRL-G j and CTRL-G k commands can be used to insert text in front of a
column. Example: >
int i;
int j;
Position the cursor on the first "int", type "istatic<C-G>j ". The
result is: >
static int i;
int j;
When inserting the same text in front of the column in every line, use the
Visual blockwise command "I" |v_b_I|.
==============================================================================
3. 'textwidth' and 'wrapmargin' options *ins-textwidth*
The 'textwidth' option can be used to automatically break a line before it
gets too long. Set the 'textwidth' option to the desired maximum line
length. If you then type more characters (not spaces or tabs), the
last word will be put on a new line (unless it is the only word on the
line). If you set 'textwidth' to 0, this feature is disabled.
The 'wrapmargin' option does almost the same. The difference is that
'textwidth' has a fixed width while 'wrapmargin' depends on the width of the
screen. When using 'wrapmargin' this is equal to using 'textwidth' with a
value equal to (columns - 'wrapmargin'), where columns is the width of the
screen.
When 'textwidth' and 'wrapmargin' are both set, 'textwidth' is used.
If you don't really want to break the line, but view the line wrapped at a
convenient place, see the 'linebreak' option.
The line is only broken automatically when using insert mode, or when
appending to a line. When in replace mode and the line length is not
changed, the line will not be broken.
Long lines are broken if you enter a non-white character after the margin.
The situations where a line will be broken can be restricted by adding
characters to the 'formatoptions' option:
"l" Only break a line if it was not longer than 'textwidth' when the insert
started.
"v" Only break at a white character that has been entered during the
current insert command. This is mostly Vi-compatible.
"lv" Only break if the line was not longer than 'textwidth' when the insert
started and only at a white character that has been entered during the
current insert command. Only differs from "l" when entering non-white
characters while crossing the 'textwidth' boundary.
If you want to format a block of text, you can use the "gq" operator. Type
"gq" and a movement command to move the cursor to the end of the block. In
many cases, the command "gq}" will do what you w
|