-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange.txt
1876 lines (1551 loc) · 74.7 KB
/
change.txt
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
*change.txt* For Vim version 8.1. Last change: 2019 Sep 27
VIM REFERENCE MANUAL by Bram Moolenaar
This file describes commands that delete or change text. In this context,
changing text means deleting the text and replacing it with other text using
one command. You can undo all of these commands. You can repeat the non-Ex
commands with the "." command.
1. Deleting text |deleting|
2. Delete and insert |delete-insert|
3. Simple changes |simple-change| *changing*
4. Complex changes |complex-change|
4.1 Filter commands |filter|
4.2 Substitute |:substitute|
4.3 Search and replace |search-replace|
4.4 Changing tabs |change-tabs|
5. Copying and moving text |copy-move|
6. Formatting text |formatting|
7. Sorting text |sorting|
For inserting text see |insert.txt|.
==============================================================================
1. Deleting text *deleting* *E470*
["x]<Del> or *<Del>* *x* *dl*
["x]x Delete [count] characters under and after the cursor
[into register x] (not |linewise|). Does the same as
"dl".
The <Del> key does not take a [count]. Instead, it
deletes the last character of the count.
See |:fixdel| if the <Del> key does not do what you
want. See |'whichwrap'| for deleting a line break
(join lines).
*X* *dh*
["x]X Delete [count] characters before the cursor [into
register x] (not |linewise|). Does the same as "dh".
Also see |'whichwrap'|.
*d*
["x]d{motion} Delete text that {motion} moves over [into register
x]. See below for exceptions.
*dd*
["x]dd Delete [count] lines [into register x] |linewise|.
*D*
["x]D Delete the characters under the cursor until the end
of the line and [count]-1 more lines [into register
x]; synonym for "d$".
(not |linewise|)
When the '#' flag is in 'cpoptions' the count is
ignored.
{Visual}["x]x or *v_x* *v_d* *v_<Del>*
{Visual}["x]d or
{Visual}["x]<Del> Delete the highlighted text [into register x] (for
{Visual} see |Visual-mode|).
{Visual}["x]CTRL-H or *v_CTRL-H* *v_<BS>*
{Visual}["x]<BS> When in Select mode: Delete the highlighted text [into
register x].
{Visual}["x]X or *v_X* *v_D* *v_b_D*
{Visual}["x]D Delete the highlighted lines [into register x] (for
{Visual} see |Visual-mode|). In Visual block mode,
"D" deletes the highlighted text plus all text until
the end of the line.
*:d* *:de* *:del* *:delete* *:dl* *:dp*
:[range]d[elete] [x] Delete [range] lines (default: current line) [into
register x].
Note these weird abbreviations:
:dl delete and list
:dell idem
:delel idem
:deletl idem
:deletel idem
:dp delete and print
:dep idem
:delp idem
:delep idem
:deletp idem
:deletep idem
:[range]d[elete] [x] {count}
Delete {count} lines, starting with [range]
(default: current line |cmdline-ranges|) [into
register x].
These commands delete text. You can repeat them with the `.` command
(except `:d`) and undo them. Use Visual mode to delete blocks of text. See
|registers| for an explanation of registers.
An exception for the d{motion} command: If the motion is not linewise, the
start and end of the motion are not in the same line, and there are only
blanks before the start and there are no non-blanks after the end of the
motion, the delete becomes linewise. This means that the delete also removes
the line of blanks that you might expect to remain. Use the |o_v| operator to
force the motion to be characterwise.
Trying to delete an empty region of text (e.g., "d0" in the first column)
is an error when 'cpoptions' includes the 'E' flag.
*J*
J Join [count] lines, with a minimum of two lines.
Remove the indent and insert up to two spaces (see
below). Fails when on the last line of the buffer.
If [count] is too big it is reduced to the number of
lines available.
*v_J*
{Visual}J Join the highlighted lines, with a minimum of two
lines. Remove the indent and insert up to two spaces
(see below).
*gJ*
gJ Join [count] lines, with a minimum of two lines.
Don't insert or remove any spaces.
*v_gJ*
{Visual}gJ Join the highlighted lines, with a minimum of two
lines. Don't insert or remove any spaces.
*:j* *:join*
:[range]j[oin][!] [flags]
Join [range] lines. Same as "J", except with [!]
the join does not insert or delete any spaces.
If a [range] has equal start and end values, this
command does nothing. The default behavior is to
join the current line with the line below it.
See |ex-flags| for [flags].
:[range]j[oin][!] {count} [flags]
Join {count} lines, starting with [range] (default:
current line |cmdline-ranges|). Same as "J", except
with [!] the join does not insert or delete any
spaces.
See |ex-flags| for [flags].
These commands delete the <EOL> between lines. This has the effect of joining
multiple lines into one line. You can repeat these commands (except `:j`) and
undo them.
These commands, except "gJ", insert one space in place of the <EOL> unless
there is trailing white space or the next line starts with a ')'. These
commands, except "gJ", delete any leading white space on the next line. If
the 'joinspaces' option is on, these commands insert two spaces after a '.',
'!' or '?' (but if 'cpoptions' includes the 'j' flag, they insert two spaces
only after a '.').
The 'B' and 'M' flags in 'formatoptions' change the behavior for inserting
spaces before and after a multi-byte character |fo-table|.
The '[ mark is set at the end of the first line that was joined, '] at the end
of the resulting line.
==============================================================================
2. Delete and insert *delete-insert* *replacing*
*R*
R Enter Replace mode: Each character you type replaces
an existing character, starting with the character
under the cursor. Repeat the entered text [count]-1
times. See |Replace-mode| for more details.
*gR*
gR Enter Virtual Replace mode: Each character you type
replaces existing characters in screen space. So a
<Tab> may replace several characters at once.
Repeat the entered text [count]-1 times. See
|Virtual-Replace-mode| for more details.
*c*
["x]c{motion} Delete {motion} text [into register x] and start
insert. When 'cpoptions' includes the 'E' flag and
there is no text to delete (e.g., with "cTx" when the
cursor is just after an 'x'), an error occurs and
insert mode does not start (this is Vi compatible).
When 'cpoptions' does not include the 'E' flag, the
"c" command always starts insert mode, even if there
is no text to delete.
*cc*
["x]cc Delete [count] lines [into register x] and start
insert |linewise|. If 'autoindent' is on, preserve
the indent of the first line.
*C*
["x]C Delete from the cursor position to the end of the
line and [count]-1 more lines [into register x], and
start insert. Synonym for c$ (not |linewise|).
*s*
["x]s Delete [count] characters [into register x] and start
insert (s stands for Substitute). Synonym for "cl"
(not |linewise|).
*S*
["x]S Delete [count] lines [into register x] and start
insert. Synonym for "cc" |linewise|.
{Visual}["x]c or *v_c* *v_s*
{Visual}["x]s Delete the highlighted text [into register x] and
start insert (for {Visual} see |Visual-mode|).
*v_r*
{Visual}["x]r{char} Replace all selected characters by {char}.
*v_C*
{Visual}["x]C Delete the highlighted lines [into register x] and
start insert. In Visual block mode it works
differently |v_b_C|.
*v_S*
{Visual}["x]S Delete the highlighted lines [into register x] and
start insert (for {Visual} see |Visual-mode|).
*v_R*
{Visual}["x]R Currently just like {Visual}["x]S. In a next version
it might work differently.
Notes:
- You can end Insert and Replace mode with <Esc>.
- See the section "Insert and Replace mode" |mode-ins-repl| for the other
special characters in these modes.
- The effect of [count] takes place after Vim exits Insert or Replace mode.
- When the 'cpoptions' option contains '$' and the change is within one line,
Vim continues to show the text to be deleted and puts a '$' at the last
deleted character.
See |registers| for an explanation of registers.
Replace mode is just like Insert mode, except that every character you enter
deletes one character. If you reach the end of a line, Vim appends any
further characters (just like Insert mode). In Replace mode, the backspace
key restores the original text (if there was any). (See section "Insert and
Replace mode" |mode-ins-repl|).
*cw* *cW*
Special case: When the cursor is in a word, "cw" and "cW" do not include the
white space after a word, they only change up to the end of the word. This is
because Vim interprets "cw" as change-word, and a word does not include the
following white space.
{Vi: "cw" when on a blank followed by other blanks changes only the first
blank; this is probably a bug, because "dw" deletes all the blanks; use the
'w' flag in 'cpoptions' to make it work like Vi anyway}
If you prefer "cw" to include the space after a word, use this mapping: >
:map cw dwi
Or use "caw" (see |aw|).
*:c* *:ch* *:change*
:{range}c[hange][!] Replace lines of text with some different text.
Type a line containing only "." to stop replacing.
Without {range}, this command changes only the current
line.
Adding [!] toggles 'autoindent' for the time this
command is executed.
==============================================================================
3. Simple changes *simple-change*
*r*
r{char} Replace the character under the cursor with {char}.
If {char} is a <CR> or <NL>, a line break replaces the
character. To replace with a real <CR>, use CTRL-V
<CR>. CTRL-V <NL> replaces with a <Nul>.
If {char} is CTRL-E or CTRL-Y the character from the
line below or above is used, just like with |i_CTRL-E|
and |i_CTRL-Y|. This also works with a count, thus
`10r<C-E>` copies 10 characters from the line below.
If you give a [count], Vim replaces [count] characters
with [count] {char}s. When {char} is a <CR> or <NL>,
however, Vim inserts only one <CR>: "5r<CR>" replaces
five characters with a single line break.
When {char} is a <CR> or <NL>, Vim performs
autoindenting. This works just like deleting the
characters that are replaced and then doing
"i<CR><Esc>".
{char} can be entered as a digraph |digraph-arg|.
|:lmap| mappings apply to {char}. The CTRL-^ command
in Insert mode can be used to switch this on/off
|i_CTRL-^|. See |utf-8-char-arg| about using
composing characters when 'encoding' is Unicode.
*gr*
gr{char} Replace the virtual characters under the cursor with
{char}. This replaces in screen space, not file
space. See |gR| and |Virtual-Replace-mode| for more
details. As with |r| a count may be given.
{char} can be entered like with |r|.
*digraph-arg*
The argument for Normal mode commands like |r| and |t| is a single character.
When 'cpo' doesn't contain the 'D' flag, this character can also be entered
like |digraphs|. First type CTRL-K and then the two digraph characters.
{not available when compiled without the |+digraphs| feature}
*case*
The following commands change the case of letters. The currently active
|locale| is used. See |:language|. The LC_CTYPE value matters here.
*~*
~ 'notildeop' option: Switch case of the character
under the cursor and move the cursor to the right.
If a [count] is given, do that many characters.
~{motion} 'tildeop' option: switch case of {motion} text.
*g~*
g~{motion} Switch case of {motion} text.
g~g~ *g~g~* *g~~*
g~~ Switch case of current line.
*v_~*
{Visual}~ Switch case of highlighted text (for {Visual} see
|Visual-mode|).
*v_U*
{Visual}U Make highlighted text uppercase (for {Visual} see
|Visual-mode|).
*gU* *uppercase*
gU{motion} Make {motion} text uppercase.
Example: >
:map! <C-F> <Esc>gUiw`]a
< This works in Insert mode: press CTRL-F to make the
word before the cursor uppercase. Handy to type
words in lowercase and then make them uppercase.
gUgU *gUgU* *gUU*
gUU Make current line uppercase.
*v_u*
{Visual}u Make highlighted text lowercase (for {Visual} see
|Visual-mode|).
*gu* *lowercase*
gu{motion} Make {motion} text lowercase.
gugu *gugu* *guu*
guu Make current line lowercase.
*g?* *rot13*
g?{motion} Rot13 encode {motion} text.
*v_g?*
{Visual}g? Rot13 encode the highlighted text (for {Visual} see
|Visual-mode|).
g?g? *g?g?* *g??*
g?? Rot13 encode current line.
To turn one line into title caps, make every first letter of a word
uppercase: >
:s/\v<(.)(\w*)/\u\1\L\2/g
Adding and subtracting ~
*CTRL-A*
CTRL-A Add [count] to the number or alphabetic character at
or after the cursor.
*v_CTRL-A*
{Visual}CTRL-A Add [count] to the number or alphabetic character in
the highlighted text.
*v_g_CTRL-A*
{Visual}g CTRL-A Add [count] to the number or alphabetic character in
the highlighted text. If several lines are
highlighted, each one will be incremented by an
additional [count] (so effectively creating a
[count] incrementing sequence).
For Example, if you have this list of numbers:
1. ~
1. ~
1. ~
1. ~
Move to the second "1." and Visually select three
lines, pressing g CTRL-A results in:
1. ~
2. ~
3. ~
4. ~
*CTRL-X*
CTRL-X Subtract [count] from the number or alphabetic
character at or after the cursor.
*v_CTRL-X*
{Visual}CTRL-X Subtract [count] from the number or alphabetic
character in the highlighted text.
On MS-Windows, this is mapped to cut Visual text
|dos-standard-mappings|. If you want to disable the
mapping, use this: >
silent! vunmap <C-X>
<
*v_g_CTRL-X*
{Visual}g CTRL-X Subtract [count] from the number or alphabetic
character in the highlighted text. If several lines
are highlighted, each value will be decremented by an
additional [count] (so effectively creating a [count]
decrementing sequence).
The CTRL-A and CTRL-X commands can work for:
- signed and unsigned decimal numbers
- unsigned binary, octal and hexadecimal numbers
- alphabetic characters
This depends on the 'nrformats' option:
- When 'nrformats' includes "bin", Vim assumes numbers starting with '0b' or
'0B' are binary.
- When 'nrformats' includes "octal", Vim considers numbers starting with a '0'
to be octal, unless the number includes a '8' or '9'. Other numbers are
decimal and may have a preceding minus sign.
If the cursor is on a number, the commands apply to that number; otherwise
Vim uses the number to the right of the cursor.
- When 'nrformats' includes "hex", Vim assumes numbers starting with '0x' or
'0X' are hexadecimal. The case of the rightmost letter in the number
determines the case of the resulting hexadecimal number. If there is no
letter in the current number, Vim uses the previously detected case.
- When 'nrformats' includes "alpha", Vim will change the alphabetic character
under or after the cursor. This is useful to make lists with an alphabetic
index.
For decimals a leading negative sign is considered for incrementing/
decrementing, for binary, octal and hex values, it won't be considered. To
ignore the sign Visually select the number before using CTRL-A or CTRL-X.
For numbers with leading zeros (including all octal and hexadecimal numbers),
Vim preserves the number of characters in the number when possible. CTRL-A on
"0077" results in "0100", CTRL-X on "0x100" results in "0x0ff".
There is one exception: When a number that starts with a zero is found not to
be octal (it contains a '8' or '9'), but 'nrformats' does include "octal",
leading zeros are removed to avoid that the result may be recognized as an
octal number.
Note that when 'nrformats' includes "octal", decimal numbers with leading
zeros cause mistakes, because they can be confused with octal numbers.
Note similarly, when 'nrformats' includes "bin", binary numbers with a leading
'0x' or '0X' can be interpreted as hexadecimal rather than binary since '0b'
are valid hexadecimal digits.
The CTRL-A command is very useful in a macro. Example: Use the following
steps to make a numbered list.
1. Create the first list entry, make sure it starts with a number.
2. qa - start recording into register 'a'
3. Y - yank the entry
4. p - put a copy of the entry below the first one
5. CTRL-A - increment the number
6. q - stop recording
7. <count>@a - repeat the yank, put and increment <count> times
SHIFTING LINES LEFT OR RIGHT *shift-left-right*
*<*
<{motion} Shift {motion} lines one 'shiftwidth' leftwards.
If the 'vartabstop' feature is enabled, and the
'shiftwidth' option is set to zero, the amount of
indent is calculated at the first non-blank character
in the line.
*<<*
<< Shift [count] lines one 'shiftwidth' leftwards.
*v_<*
{Visual}[count]< Shift the highlighted lines [count] 'shiftwidth'
leftwards (for {Visual} see |Visual-mode|).
*>*
>{motion} Shift {motion} lines one 'shiftwidth' rightwards.
If the 'vartabstop' feature is enabled, and the
'shiftwidth' option is set to zero, the amount of
indent is calculated at the first non-blank character
in the line.
*>>*
>> Shift [count] lines one 'shiftwidth' rightwards.
*v_>*
{Visual}[count]> Shift the highlighted lines [count] 'shiftwidth'
rightwards (for {Visual} see |Visual-mode|).
*:<*
:[range]< Shift [range] lines one 'shiftwidth' left. Repeat '<'
for shifting multiple 'shiftwidth's.
:[range]< {count} Shift {count} lines one 'shiftwidth' left, starting
with [range] (default current line |cmdline-ranges|).
Repeat '<' for shifting multiple 'shiftwidth's.
:[range]le[ft] [indent] left align lines in [range]. Sets the indent in the
lines to [indent] (default 0).
*:>*
:[range]> [flags] Shift {count} [range] lines one 'shiftwidth' right.
Repeat '>' for shifting multiple 'shiftwidth's.
See |ex-flags| for [flags].
:[range]> {count} [flags]
Shift {count} lines one 'shiftwidth' right, starting
with [range] (default current line |cmdline-ranges|).
Repeat '>' for shifting multiple 'shiftwidth's.
See |ex-flags| for [flags].
The ">" and "<" commands are handy for changing the indentation within
programs. Use the 'shiftwidth' option to set the size of the white space
which these commands insert or delete. Normally the 'shiftwidth' option is 8,
but you can set it to, say, 3 to make smaller indents. The shift leftwards
stops when there is no indent. The shift right does not affect empty lines.
If the 'shiftround' option is on, the indent is rounded to a multiple of
'shiftwidth'.
If the 'smartindent' option is on, or 'cindent' is on and 'cinkeys' contains
'#' with a zero value, shift right does not affect lines starting with '#'
(these are supposed to be C preprocessor lines that must stay in column 1).
This can be changed with the 'cino' option, see |cino-#|.
When the 'expandtab' option is off (this is the default) Vim uses <Tab>s as
much as possible to make the indent. You can use ">><<" to replace an indent
made out of spaces with the same indent made out of <Tab>s (and a few spaces
if necessary). If the 'expandtab' option is on, Vim uses only spaces. Then
you can use ">><<" to replace <Tab>s in the indent by spaces (or use
`:retab!`).
To move a line several 'shiftwidth's, use Visual mode or the `:` commands.
For example: >
Vjj4> move three lines 4 indents to the right
:<<< move current line 3 indents to the left
:>> 5 move 5 lines 2 indents to the right
:5>> move line 5 2 indents to the right
==============================================================================
4. Complex changes *complex-change*
4.1 Filter commands *filter*
A filter is a program that accepts text at standard input, changes it in some
way, and sends it to standard output. You can use the commands below to send
some text through a filter, so that it is replaced by the filter output.
Examples of filters are "sort", which sorts lines alphabetically, and
"indent", which formats C program files (you need a version of indent that
works like a filter; not all versions do). The 'shell' option specifies the
shell Vim uses to execute the filter command (See also the 'shelltype'
option). You can repeat filter commands with ".". Vim does not recognize a
comment (starting with '"') after the `:!` command.
*!*
!{motion}{filter} Filter {motion} text lines through the external
program {filter}.
*!!*
!!{filter} Filter [count] lines through the external program
{filter}.
*v_!*
{Visual}!{filter} Filter the highlighted lines through the external
program {filter} (for {Visual} see |Visual-mode|).
:{range}![!]{filter} [!][arg] *:range!*
Filter {range} lines through the external program
{filter}. Vim replaces the optional bangs with the
latest given command and appends the optional [arg].
Vim saves the output of the filter command in a
temporary file and then reads the file into the buffer
|tempfile|. Vim uses the 'shellredir' option to
redirect the filter output to the temporary file.
However, if the 'shelltemp' option is off then pipes
are used when possible (on Unix).
When the 'R' flag is included in 'cpoptions' marks in
the filtered lines are deleted, unless the
|:keepmarks| command is used. Example: >
:keepmarks '<,'>!sort
< When the number of lines after filtering is less than
before, marks in the missing lines are deleted anyway.
*=*
={motion} Filter {motion} lines through the external program
given with the 'equalprg' option. When the 'equalprg'
option is empty (this is the default), use the
internal formatting function |C-indenting| and
|'lisp'|. But when 'indentexpr' is not empty, it will
be used instead |indent-expression|. When Vim was
compiled without internal formatting then the "indent"
program is used as a last resort.
*==*
== Filter [count] lines like with ={motion}.
*v_=*
{Visual}= Filter the highlighted lines like with ={motion}.
*tempfile* *setuid*
Vim uses temporary files for filtering, generating diffs and also for
tempname(). For Unix, the file will be in a private directory (only
accessible by the current user) to avoid security problems (e.g., a symlink
attack or other people reading your file). When Vim exits the directory and
all files in it are deleted. When Vim has the setuid bit set this may cause
problems, the temp file is owned by the setuid user but the filter command
probably runs as the original user.
On MS-DOS and OS/2 the first of these directories that works is used: $TMP,
$TEMP, c:\TMP, c:\TEMP.
For Unix the list of directories is: $TMPDIR, /tmp, current-dir, $HOME.
For MS-Windows the GetTempFileName() system function is used.
For other systems the tmpnam() library function is used.
4.2 Substitute *:substitute*
*:s* *:su*
:[range]s[ubstitute]/{pattern}/{string}/[flags] [count]
For each line in [range] replace a match of {pattern}
with {string}.
For the {pattern} see |pattern|.
{string} can be a literal string, or something
special; see |sub-replace-special|.
When [range] and [count] are omitted, replace in the
current line only. When [count] is given, replace in
[count] lines, starting with the last line in [range].
When [range] is omitted start in the current line.
*E939*
[count] must be a positive number. Also see
|cmdline-ranges|.
See |:s_flags| for [flags].
:[range]s[ubstitute] [flags] [count]
:[range]&[&][flags] [count] *:&*
Repeat last :substitute with same search pattern and
substitute string, but without the same flags. You
may add [flags], see |:s_flags|.
Note that after `:substitute` the '&' flag can't be
used, it's recognized as a pattern separator.
The space between `:substitute` and the 'c', 'g',
'i', 'I' and 'r' flags isn't required, but in scripts
it's a good idea to keep it to avoid confusion.
:[range]~[&][flags] [count] *:~*
Repeat last substitute with same substitute string
but with last used search pattern. This is like
`:&r`. See |:s_flags| for [flags].
*&*
& Synonym for `:s` (repeat last substitute). Note
that the flags are not remembered, thus it might
actually work differently. You can use `:&&` to keep
the flags.
*g&*
g& Synonym for `:%s//~/&` (repeat last substitute with
last search pattern on all lines with the same flags).
For example, when you first do a substitution with
`:s/pattern/repl/flags` and then `/search` for
something else, `g&` will do `:%s/search/repl/flags`.
Mnemonic: global substitute.
*:snomagic* *:sno*
:[range]sno[magic] ... Same as `:substitute`, but always use 'nomagic'.
*:smagic* *:sm*
:[range]sm[agic] ... Same as `:substitute`, but always use 'magic'.
*:s_flags*
The flags that you can use for the substitute commands:
*:&&*
[&] Must be the first one: Keep the flags from the previous substitute
command. Examples: >
:&&
:s/this/that/&
< Note that `:s` and `:&` don't keep the flags.
[c] Confirm each substitution. Vim highlights the matching string (with
|hl-IncSearch|). You can type: *:s_c*
'y' to substitute this match
'l' to substitute this match and then quit ("last")
'n' to skip this match
<Esc> to quit substituting
'a' to substitute this and all remaining matches
'q' to quit substituting
CTRL-E to scroll the screen up
CTRL-Y to scroll the screen down
If the 'edcompatible' option is on, Vim remembers the [c] flag and
toggles it each time you use it, but resets it when you give a new
search pattern.
*:s_e*
[e] When the search pattern fails, do not issue an error message and, in
particular, continue in maps as if no error occurred. This is most
useful to prevent the "No match" error from breaking a mapping. Vim
does not suppress the following error messages, however:
Regular expressions can't be delimited by letters
\ should be followed by /, ? or &
No previous substitute regular expression
Trailing characters
Interrupted
*:s_g*
[g] Replace all occurrences in the line. Without this argument,
replacement occurs only for the first occurrence in each line. If
the 'edcompatible' option is on, Vim remembers this flag and toggles
it each time you use it, but resets it when you give a new search
pattern. If the 'gdefault' option is on, this flag is on by default
and the [g] argument switches it off.
*:s_i*
[i] Ignore case for the pattern. The 'ignorecase' and 'smartcase' options
are not used.
*:s_I*
[I] Don't ignore case for the pattern. The 'ignorecase' and 'smartcase'
options are not used.
*:s_n*
[n] Report the number of matches, do not actually substitute. The [c]
flag is ignored. The matches are reported as if 'report' is zero.
Useful to |count-items|.
If \= |sub-replace-expression| is used, the expression will be
evaluated in the |sandbox| at every match.
[p] Print the line containing the last substitute. *:s_p*
[#] Like [p] and prepend the line number. *:s_#*
[l] Like [p] but print the text like |:list|. *:s_l*
*:s_r*
[r] Only useful in combination with `:&` or `:s` without arguments. `:&r`
works the same way as `:~`: When the search pattern is empty, use the
previously used search pattern instead of the search pattern from the
last substitute or `:global`. If the last command that did a search
was a substitute or `:global`, there is no effect. If the last
command was a search command such as "/", use the pattern from that
command.
For `:s` with an argument this already happens: >
:s/blue/red/
/green
:s//red/ or :~ or :&r
< The last commands will replace "green" with "red". >
:s/blue/red/
/green
:&
< The last command will replace "blue" with "red".
Note that there is no flag to change the "magicness" of the pattern. A
different command is used instead, or you can use |/\v| and friends. The
reason is that the flags can only be found by skipping the pattern, and in
order to skip the pattern the "magicness" must be known. Catch 22!
If the {pattern} for the substitute command is empty, the command uses the
pattern from the last substitute or `:global` command. If there is none, but
there is a previous search pattern, that one is used. With the [r] flag, the
command uses the pattern from the last substitute, `:global`, or search
command.
If the {string} is omitted the substitute is done as if it's empty. Thus the
matched pattern is deleted. The separator after {pattern} can also be left
out then. Example: >
:%s/TESTING
This deletes "TESTING" from all lines, but only one per line.
For compatibility with Vi these two exceptions are allowed:
"\/{string}/" and "\?{string}?" do the same as "//{string}/r".
"\&{string}&" does the same as "//{string}/".
*E146*
Instead of the '/' which surrounds the pattern and replacement string, you
can use any other single-byte character, but not an alphanumeric character,
'\', '"' or '|'. This is useful if you want to include a '/' in the search
pattern or replacement string. Example: >
:s+/+//+
For the definition of a pattern, see |pattern|. In Visual block mode, use
|/\%V| in the pattern to have the substitute work in the block only.
Otherwise it works on whole lines anyway.
*sub-replace-special* *:s\=*
When the {string} starts with "\=" it is evaluated as an expression, see
|sub-replace-expression|. You can use that for complex replacement or special
characters.
Otherwise these characters in {string} have a special meaning:
*:s%*
When {string} is equal to "%" and '/' is included with the 'cpoptions' option,
then the {string} of the previous substitute command is used, see |cpo-/|
magic nomagic action ~
& \& replaced with the whole matched pattern *s/\&*
\& & replaced with &
\0 replaced with the whole matched pattern *\0* *s/\0*
\1 replaced with the matched pattern in the first
pair of () *s/\1*
\2 replaced with the matched pattern in the second
pair of () *s/\2*
.. .. *s/\3*
\9 replaced with the matched pattern in the ninth
pair of () *s/\9*
~ \~ replaced with the {string} of the previous
substitute *s~*
\~ ~ replaced with ~ *s/\~*
\u next character made uppercase *s/\u*
\U following characters made uppercase, until \E *s/\U*
\l next character made lowercase *s/\l*
\L following characters made lowercase, until \E *s/\L*
\e end of \u, \U, \l and \L (NOTE: not <Esc>!) *s/\e*
\E end of \u, \U, \l and \L *s/\E*
<CR> split line in two at this point
(Type the <CR> as CTRL-V <Enter>) *s<CR>*
\r idem *s/\r*
\<CR> insert a carriage-return (CTRL-M)
(Type the <CR> as CTRL-V <Enter>) *s/\<CR>*
\n insert a <NL> (<NUL> in the file)
(does NOT break the line) *s/\n*
\b insert a <BS> *s/\b*
\t insert a <Tab> *s/\t*
\\ insert a single backslash *s/\\*
\x where x is any character not mentioned above:
Reserved for future expansion
The special meaning is also used inside the third argument {sub} of
the |substitute()| function with the following exceptions:
- A % inserts a percent literally without regard to 'cpoptions'.
- magic is always set without regard to 'magic'.
- A ~ inserts a tilde literally.
- <CR> and \r inserts a carriage-return (CTRL-M).
- \<CR> does not have a special meaning. It's just one of \x.
Examples: >
:s/a\|b/xxx\0xxx/g modifies "a b" to "xxxaxxx xxxbxxx"
:s/\([abc]\)\([efg]\)/\2\1/g modifies "af fa bg" to "fa fa gb"
:s/abcde/abc^Mde/ modifies "abcde" to "abc", "de" (two lines)
:s/$/\^M/ modifies "abcde" to "abcde^M"
:s/\w\+/\u\0/g modifies "bla bla" to "Bla Bla"
:s/\w\+/\L\u\0/g modifies "BLA bla" to "Bla Bla"
Note: "\L\u" can be used to capitalize the first letter of a word. This is
not compatible with Vi and older versions of Vim, where the "\u" would cancel
out the "\L". Same for "\U\l".
Note: In previous versions CTRL-V was handled in a special way. Since this is
not Vi compatible, this was removed. Use a backslash instead.
command text result ~
:s/aa/a^Ma/ aa a<line-break>a
:s/aa/a\^Ma/ aa a^Ma
:s/aa/a\\^Ma/ aa a\<line-break>a
(you need to type CTRL-V <CR> to get a ^M here)
The numbering of "\1", "\2" etc. is done based on which "\(" comes first in
the pattern (going left to right). When a parentheses group matches several
times, the last one will be used for "\1", "\2", etc. Example: >
:s/\(\(a[a-d] \)*\)/\2/ modifies "aa ab x" to "ab x"
The "\2" is for "\(a[a-d] \)". At first it matches "aa ", secondly "ab ".
When using parentheses in combination with '|', like in \([ab]\)\|\([cd]\),
either the first or second pattern in parentheses did not match, so either
\1 or \2 is empty. Example: >
:s/\([ab]\)\|\([cd]\)/\1x/g modifies "a b c d" to "ax bx x x"
<
*:sc* *:sce* *:scg* *:sci* *:scI* *:scl* *:scp* *:sg* *:sgc*
*:sge* *:sgi* *:sgI* *:sgl* *:sgn* *:sgp* *:sgr* *:sI* *:si*
*:sic* *:sIc* *:sie* *:sIe* *:sIg* *:sIl* *:sin* *:sIn* *:sIp*
*:sip* *:sIr* *:sir* *:sr* *:src* *:srg* *:sri* *:srI* *:srl*
*:srn* *:srp*
2-letter and 3-letter :substitute commands ~
List of :substitute commands
| c e g i I n p l r
| c :sc :sce :scg :sci :scI :scn :scp :scl ---
| e
| g :sgc :sge :sg :sgi :sgI :sgn :sgp :sgl :sgr
| i :sic :sie --- :si :siI :sin :sip --- :sir
| I :sIc :sIe :sIg :sIi :sI :sIn :sIp :sIl :sIr
| n
| p
| l
| r :src --- :srg :sri :srI :srn :srp :srl :sr
Exceptions:
:scr is `:scriptnames`
:se is `:set`
:sig is `:sign`
:sil is `:silent`
:sn is `:snext`
:sp is `:split`
:sl is `:sleep`
:sre is `:srewind`
Substitute with an expression *sub-replace-expression*
*sub-replace-\=* *s/\=*
When the substitute string starts with "\=" the remainder is interpreted as an
expression.
The special meaning for characters as mentioned at |sub-replace-special| does
not apply except for "<CR>". A <NL> character is used as a line break, you
can get one with a double-quote string: "\n". Prepend a backslash to get a
real <NL> character (which will be a NUL in the file).
The "\=" notation can also be used inside the third argument {sub} of
|substitute()| function. In this case, the special meaning for characters as
mentioned at |sub-replace-special| does not apply at all. Especially, <CR> and
<NL> are interpreted not as a line break but as a carriage-return and a
new-line respectively.
When the result is a |List| then the items are joined with separating line
breaks. Thus each item becomes a line, except that they can contain line
breaks themselves.
The |submatch()| function can be used to obtain matched text. The whole
matched text can be accessed with "submatch(0)". The text matched with the
first pair of () with "submatch(1)". Likewise for further sub-matches in ().
Be careful: The separation character must not appear in the expression!
Consider using a character like "@" or ":". There is no problem if the result
of the expression contains the separation character.
Examples: >
:s@\n@\="\r" . expand("$HOME") . "\r"@
This replaces an end-of-line with a new line containing the value of $HOME. >
s/E/\="\<Char-0x20ac>"/g
This replaces each 'E' character with a euro sign. Read more in |<Char->|.
4.3 Search and replace *search-replace*
*:pro* *:promptfind*
:promptf[ind] [string]
Put up a Search dialog. When [string] is given, it is
used as the initial search string.
{only for Win32, Motif and GTK GUI}
*:promptr* *:promptrepl*
:promptr[epl] [string]
Put up a Search/Replace dialog. When [string] is
given, it is used as the initial search string.
{only for Win32, Motif and GTK GUI}
4.4 Changing tabs *change-tabs*
*:ret* *:retab* *:retab!*
:[range]ret[ab][!] [new_tabstop]
Replace all sequences of white-space containing a
<Tab> with new strings of white-space using the new
tabstop value given. If you do not specify a new
tabstop size or it is zero, Vim uses the current value
of 'tabstop'.
The current value of 'tabstop' is always used to
compute the width of existing tabs.
With !, Vim also replaces strings of only normal
spaces with tabs where appropriate.
With 'expandtab' on, Vim replaces all tabs with the
appropriate number of spaces.
This command sets 'tabstop' to the new value given,
and if performed on the whole file, which is default,
should not make any visible change.
Careful: This command modifies any <Tab> characters
inside of strings in a C program. Use "\t" to avoid
this (that's a good habit anyway).
`:retab!` may also change a sequence of spaces by
<Tab> characters, which can mess up a printf().
If the |+vartabs| feature is enabled then a list of
tab widths separated by commas may be used in place of
a single tabstop. Each value in the list represents
the width of one tabstop, except the final value which
applies to all following tabstops.
*retab-example*
Example for using autocommands and ":retab" to edit a file which is stored
with tabstops at 8 but edited with tabstops set at 4. Warning: white space
inside of strings can change! Also see 'softtabstop' option. >
:auto BufReadPost *.xx retab! 4
:auto BufWritePre *.xx retab! 8
:auto BufWritePost *.xx retab! 4
:auto BufNewFile *.xx set ts=4
==============================================================================
5. Copying and moving text *copy-move*
*quote*
"{a-zA-Z0-9.%#:-"} Use register {a-zA-Z0-9.%#:-"} for next delete, yank
or put (use uppercase character to append with
delete and yank) ({.%#:} only work with put).