/
usr
/
share
/
vim
/
vim91
/
doc
/
/usr/share/vim/vim91/doc
mkdir
upload
Name
Size
Mode
Actions
arabic.txt
12204
0644
edit
dl
rm
autocmd.txt
77872
0644
edit
dl
rm
builtin.txt
432001
0644
edit
dl
rm
change.txt
80714
0644
edit
dl
rm
channel.txt
59103
0644
edit
dl
rm
cmdline.txt
53181
0644
edit
dl
rm
debug.txt
6896
0644
edit
dl
rm
debugger.txt
5443
0644
edit
dl
rm
develop.txt
23118
0644
edit
dl
rm
diff.txt
18341
0644
edit
dl
rm
digraph.txt
62443
0644
edit
dl
rm
editing.txt
77499
0644
edit
dl
rm
eval.txt
173232
0644
edit
dl
rm
farsi.txt
523
0644
edit
dl
rm
filetype.txt
30622
0644
edit
dl
rm
fold.txt
24730
0644
edit
dl
rm
ft_ada.txt
18212
0644
edit
dl
rm
ft_context.txt
5161
0644
edit
dl
rm
ft_mp.txt
4706
0644
edit
dl
rm
ft_ps1.txt
2187
0644
edit
dl
rm
ft_raku.txt
4219
0644
edit
dl
rm
ft_rust.txt
19800
0644
edit
dl
rm
ft_sql.txt
30694
0644
edit
dl
rm
gui.txt
53499
0644
edit
dl
rm
gui_w32.txt
19123
0644
edit
dl
rm
gui_x11.txt
29318
0644
edit
dl
rm
hangulin.txt
598
0644
edit
dl
rm
hebrew.txt
5666
0644
edit
dl
rm
help.txt
9491
0644
edit
dl
rm
help.txt.vim-tiny
1350
0644
edit
dl
rm
helphelp.txt
16060
0644
edit
dl
rm
howto.txt
2916
0644
edit
dl
rm
if_cscop.txt
19325
0644
edit
dl
rm
if_lua.txt
18546
0644
edit
dl
rm
if_mzsch.txt
11941
0644
edit
dl
rm
if_ole.txt
7117
0644
edit
dl
rm
if_perl.txt
11451
0644
edit
dl
rm
if_pyth.txt
40820
0644
edit
dl
rm
if_ruby.txt
8516
0644
edit
dl
rm
if_sniff.txt
271
0644
edit
dl
rm
if_tcl.txt
22948
0644
edit
dl
rm
indent.txt
43699
0644
edit
dl
rm
index.txt
82373
0644
edit
dl
rm
insert.txt
88124
0644
edit
dl
rm
intro.txt
39623
0644
edit
dl
rm
map.txt
81176
0644
edit
dl
rm
mbyte.txt
58640
0644
edit
dl
rm
message.txt
31931
0644
edit
dl
rm
mlang.txt
8160
0644
edit
dl
rm
motion.txt
54387
0644
edit
dl
rm
netbeans.txt
37957
0644
edit
dl
rm
options.txt
419402
0644
edit
dl
rm
os_390.txt
4741
0644
edit
dl
rm
os_amiga.txt
5466
0644
edit
dl
rm
os_beos.txt
293
0644
edit
dl
rm
os_dos.txt
15495
0644
edit
dl
rm
os_haiku.txt
8543
0644
edit
dl
rm
os_mac.txt
6856
0644
edit
dl
rm
os_mint.txt
391
0644
edit
dl
rm
os_msdos.txt
523
0644
edit
dl
rm
os_os2.txt
299
0644
edit
dl
rm
os_qnx.txt
4071
0644
edit
dl
rm
os_risc.txt
328
0644
edit
dl
rm
os_unix.txt
2607
0644
edit
dl
rm
os_vms.txt
33743
0644
edit
dl
rm
os_win32.txt
14912
0644
edit
dl
rm
pattern.txt
63653
0644
edit
dl
rm
pi_getscript.txt
21077
0644
edit
dl
rm
pi_gzip.txt
1547
0644
edit
dl
rm
pi_logipat.txt
4196
0644
edit
dl
rm
pi_netrw.txt
181735
0644
edit
dl
rm
pi_paren.txt
2274
0644
edit
dl
rm
pi_spec.txt
4127
0644
edit
dl
rm
pi_tar.txt
7191
0644
edit
dl
rm
pi_vimball.txt
11859
0644
edit
dl
rm
pi_zip.txt
7778
0644
edit
dl
rm
popup.txt
40382
0644
edit
dl
rm
print.txt
31445
0644
edit
dl
rm
quickfix.txt
85701
0644
edit
dl
rm
quickref.txt
73061
0644
edit
dl
rm
quotes.txt
12748
0644
edit
dl
rm
README.Debian
324
0644
edit
dl
rm
recover.txt
10727
0644
edit
dl
rm
remote.txt
8626
0644
edit
dl
rm
repeat.txt
46502
0644
edit
dl
rm
rileft.txt
5063
0644
edit
dl
rm
russian.txt
3024
0644
edit
dl
rm
scroll.txt
14356
0644
edit
dl
rm
sign.txt
26860
0644
edit
dl
rm
spell.txt
64205
0644
edit
dl
rm
sponsor.txt
6776
0644
edit
dl
rm
starting.txt
74540
0644
edit
dl
rm
syntax.txt
237597
0644
edit
dl
rm
tabpage.txt
17246
0644
edit
dl
rm
tags
391091
0644
edit
dl
rm
tags.vim-tiny
1935
0644
edit
dl
rm
tagsrch.txt
40475
0644
edit
dl
rm
term.txt
55685
0644
edit
dl
rm
terminal.txt
63169
0644
edit
dl
rm
testing.txt
22507
0644
edit
dl
rm
textprop.txt
20478
0644
edit
dl
rm
tips.txt
21336
0644
edit
dl
rm
todo.txt
316358
0644
edit
dl
rm
uganda.txt
13052
0644
edit
dl
rm
undo.txt
17811
0644
edit
dl
rm
userfunc.txt
20624
0644
edit
dl
rm
usr_01.txt
7076
0644
edit
dl
rm
usr_02.txt
24228
0644
edit
dl
rm
usr_03.txt
23934
0644
edit
dl
rm
usr_04.txt
19131
0644
edit
dl
rm
usr_05.txt
27946
0644
edit
dl
rm
usr_06.txt
10639
0644
edit
dl
rm
usr_07.txt
15995
0644
edit
dl
rm
usr_08.txt
19379
0644
edit
dl
rm
usr_09.txt
11502
0644
edit
dl
rm
usr_10.txt
29200
0644
edit
dl
rm
usr_11.txt
13025
0644
edit
dl
rm
usr_12.txt
13433
0644
edit
dl
rm
usr_20.txt
13733
0644
edit
dl
rm
usr_21.txt
18456
0644
edit
dl
rm
usr_22.txt
14904
0644
edit
dl
rm
usr_23.txt
12744
0644
edit
dl
rm
usr_24.txt
20827
0644
edit
dl
rm
usr_25.txt
19176
0644
edit
dl
rm
usr_26.txt
8259
0644
edit
dl
rm
usr_27.txt
17709
0644
edit
dl
rm
usr_28.txt
16020
0644
edit
dl
rm
usr_29.txt
20259
0644
edit
dl
rm
usr_30.txt
22658
0644
edit
dl
rm
usr_31.txt
10399
0644
edit
dl
rm
usr_32.txt
5378
0644
edit
dl
rm
usr_40.txt
23554
0644
edit
dl
rm
usr_41.txt
65272
0644
edit
dl
rm
usr_42.txt
13853
0644
edit
dl
rm
usr_43.txt
7409
0644
edit
dl
rm
usr_44.txt
28948
0644
edit
dl
rm
usr_45.txt
17680
0644
edit
dl
rm
usr_50.txt
4554
0644
edit
dl
rm
usr_51.txt
25517
0644
edit
dl
rm
usr_52.txt
13498
0644
edit
dl
rm
usr_90.txt
16778
0644
edit
dl
rm
usr_toc.txt
9886
0644
edit
dl
rm
various.txt
32432
0644
edit
dl
rm
version4.txt
13911
0644
edit
dl
rm
version5.txt
308529
0644
edit
dl
rm
version6.txt
576942
0644
edit
dl
rm
version7.txt
674698
0644
edit
dl
rm
version8.txt
1599852
0644
edit
dl
rm
version9.txt
1611325
0644
edit
dl
rm
vim9.txt
91753
0644
edit
dl
rm
vim9class.txt
41040
0644
edit
dl
rm
visual.txt
22625
0644
edit
dl
rm
vi_diff.txt
57404
0644
edit
dl
rm
windows.txt
58706
0644
edit
dl
rm
workshop.txt
371
0644
edit
dl
rm
Edit:
/usr/share/vim/vim91/doc/usr_26.txt
(8259B)
*usr_26.txt* For Vim version 9.1. Last change: 2006 Apr 24 VIM USER MANUAL - by Bram Moolenaar Repeating An editing task is hardly ever unstructured. A change often needs to be made several times. In this chapter a number of useful ways to repeat a change will be explained. |26.1| Repeating with Visual mode |26.2| Add and subtract |26.3| Making a change in many files |26.4| Using Vim from a shell script Next chapter: |usr_27.txt| Search commands and patterns Previous chapter: |usr_25.txt| Editing formatted text Table of contents: |usr_toc.txt| ============================================================================== *26.1* Repeating with Visual mode Visual mode is very handy for making a change in any sequence of lines. You can see the highlighted text, thus you can check if the correct lines are changed. But making the selection takes some typing. The "gv" command selects the same area again. This allows you to do another operation on the same text. Suppose you have some lines where you want to change "2001" to "2002" and "2000" to "2001": The financial results for 2001 are better ~ than for 2000. The income increased by 50%, ~ even though 2001 had more rain than 2000. ~ 2000 2001 ~ income 45,403 66,234 ~ First change "2001" to "2002". Select the lines in Visual mode, and use: > :s/2001/2002/g Now use "gv" to reselect the same text. It doesn't matter where the cursor is. Then use ":s/2000/2001/g" to make the second change. Obviously, you can repeat these changes several times. ============================================================================== *26.2* Add and subtract When repeating the change of one number into another, you often have a fixed offset. In the example above, one was added to each year. Instead of typing a substitute command for each year that appears, the CTRL-A command can be used. Using the same text as above, search for a year: > /19[0-9][0-9]\|20[0-9][0-9] Now press CTRL-A. The year will be increased by one: The financial results for 2002 are better ~ than for 2000. The income increased by 50%, ~ even though 2001 had more rain than 2000. ~ 2000 2001 ~ income 45,403 66,234 ~ Use "n" to find the next year, and press "." to repeat the CTRL-A ("." is a bit quicker to type). Repeat "n" and "." for all years that appear. Hint: set the 'hlsearch' option to see the matches you are going to change, then you can look ahead and do it faster. Adding more than one can be done by prepending the number to CTRL-A. Suppose you have this list: 1. item four ~ 2. item five ~ 3. item six ~ Move the cursor to "1." and type: > 3 CTRL-A The "1." will change to "4.". Again, you can use "." to repeat this on the other numbers. Another example: 006 foo bar ~ 007 foo bar ~ Using CTRL-A on these numbers results in: 007 foo bar ~ 010 foo bar ~ 7 plus one is 10? What happened here is that Vim recognized "007" as an octal number, because there is a leading zero. This notation is often used in C programs. If you do not want a number with leading zeros to be handled as octal, use this: > :set nrformats-=octal The CTRL-X command does subtraction in a similar way. ============================================================================== *26.3* Making a change in many files Suppose you have a variable called "x_cnt" and you want to change it to "x_counter". This variable is used in several of your C files. You need to change it in all files. This is how you do it. Put all the relevant files in the argument list: > :args *.c < This finds all C files and edits the first one. Now you can perform a substitution command on all these files: > :argdo %s/\<x_cnt\>/x_counter/ge | update The ":argdo" command takes an argument that is another command. That command will be executed on all files in the argument list. The "%s" substitute command that follows works on all lines. It finds the word "x_cnt" with "\<x_cnt\>". The "\<" and "\>" are used to match the whole word only, and not "px_cnt" or "x_cnt2". The flags for the substitute command include "g" to replace all occurrences of "x_cnt" in the same line. The "e" flag is used to avoid an error message when "x_cnt" does not appear in the file. Otherwise ":argdo" would abort on the first file where "x_cnt" was not found. The "|" separates two commands. The following "update" command writes the file only if it was changed. If no "x_cnt" was changed to "x_counter" nothing happens. There is also the ":windo" command, which executes its argument in all windows. And ":bufdo" executes its argument on all buffers. Be careful with this, because you might have more files in the buffer list than you think. Check this with the ":buffers" command (or ":ls"). ============================================================================== *26.4* Using Vim from a shell script Suppose you have a lot of files in which you need to change the string "-person-" to "Jones" and then print it. How do you do that? One way is to do a lot of typing. The other is to write a shell script to do the work. The Vim editor does a superb job as a screen-oriented editor when using Normal mode commands. For batch processing, however, Normal mode commands do not result in clear, commented command files; so here you will use Ex mode instead. This mode gives you a nice command-line interface that makes it easy to put into a batch file. ("Ex command" is just another name for a command-line (:) command.) The Ex mode commands you need are as follows: > %s/-person-/Jones/g write tempfile quit You put these commands in the file "change.vim". Now to run the editor in batch mode, use this shell script: > for file in *.txt; do vim -e -s $file < change.vim lpr -r tempfile done The for-done loop is a shell construct to repeat the two lines in between, while the $file variable is set to a different file name each time. The second line runs the Vim editor in Ex mode (-e argument) on the file $file and reads commands from the file "change.vim". The -s argument tells Vim to operate in silent mode. In other words, do not keep outputting the :prompt, or any other prompt for that matter. The "lpr -r tempfile" command prints the resulting "tempfile" and deletes it (that's what the -r argument does). READING FROM STDIN Vim can read text on standard input. Since the normal way is to read commands there, you must tell Vim to read text instead. This is done by passing the "-" argument in place of a file. Example: > ls | vim - This allows you to edit the output of the "ls" command, without first saving the text in a file. If you use the standard input to read text from, you can use the "-S" argument to read a script: > producer | vim -S change.vim - NORMAL MODE SCRIPTS If you really want to use Normal mode commands in a script, you can use it like this: > vim -s script file.txt ... < Note: "-s" has a different meaning when it is used without "-e". Here it means to source the "script" as Normal mode commands. When used with "-e" it means to be silent, and doesn't use the next argument as a file name. The commands in "script" are executed like you typed them. Don't forget that a line break is interpreted as pressing <Enter>. In Normal mode that moves the cursor to the next line. To create the script you can edit the script file and type the commands. You need to imagine what the result would be, which can be a bit difficult. Another way is to record the commands while you perform them manually. This is how you do that: > vim -w script file.txt ... All typed keys will be written to "script". If you make a small mistake you can just continue and remember to edit the script later. The "-w" argument appends to an existing script. That is good when you want to record the script bit by bit. If you want to start from scratch and start all over, use the "-W" argument. It overwrites any existing file. ============================================================================== Next chapter: |usr_27.txt| Search commands and patterns Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl:
Save
cmd:
run