$88 GRAYBYTE WORDPRESS FILE MANAGER $77

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/usr/share/vim/vim80/doc/

HOME
Current File : /usr/share/vim/vim80/doc//usr_26.txt
*usr_26.txt*	For Vim version 8.0.  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:ft=help:norl:

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
16 Dec 2025 9.30 PM
root / root
0755
arabic.txt
11.656 KB
12 Oct 2025 7.23 AM
root / root
0644
autocmd.txt
63.869 KB
12 Oct 2025 7.23 AM
root / root
0644
change.txt
73.122 KB
12 Oct 2025 7.23 AM
root / root
0644
channel.txt
30.097 KB
12 Oct 2025 7.23 AM
root / root
0644
cmdline.txt
46.175 KB
12 Oct 2025 7.23 AM
root / root
0644
debug.txt
7.014 KB
12 Oct 2025 7.23 AM
root / root
0644
debugger.txt
5.609 KB
12 Oct 2025 7.23 AM
root / root
0644
develop.txt
21.82 KB
12 Oct 2025 7.23 AM
root / root
0644
diff.txt
16.138 KB
12 Oct 2025 7.23 AM
root / root
0644
digraph.txt
60.667 KB
12 Oct 2025 7.23 AM
root / root
0644
editing.txt
71.461 KB
12 Oct 2025 7.23 AM
root / root
0644
eval.txt
434.045 KB
12 Oct 2025 7.23 AM
root / root
0644
farsi.txt
9.476 KB
12 Oct 2025 7.23 AM
root / root
0644
filetype.txt
25.325 KB
12 Oct 2025 7.23 AM
root / root
0644
fold.txt
23.139 KB
12 Oct 2025 7.23 AM
root / root
0644
ft_ada.txt
17.819 KB
12 Oct 2025 7.23 AM
root / root
0644
ft_rust.txt
9.303 KB
12 Oct 2025 7.23 AM
root / root
0644
ft_sql.txt
29.975 KB
12 Oct 2025 7.23 AM
root / root
0644
gui.txt
44.523 KB
12 Oct 2025 7.23 AM
root / root
0644
gui_w32.txt
18.473 KB
12 Oct 2025 7.23 AM
root / root
0644
gui_x11.txt
28.789 KB
12 Oct 2025 7.23 AM
root / root
0644
hangulin.txt
3.214 KB
12 Oct 2025 7.23 AM
root / root
0644
hebrew.txt
5.58 KB
12 Oct 2025 7.23 AM
root / root
0644
help.txt
8.377 KB
12 Oct 2025 7.23 AM
root / root
0644
helphelp.txt
14.002 KB
12 Oct 2025 7.23 AM
root / root
0644
howto.txt
2.843 KB
12 Oct 2025 7.23 AM
root / root
0644
if_cscop.txt
18.907 KB
12 Oct 2025 7.23 AM
root / root
0644
if_lua.txt
14.299 KB
12 Oct 2025 7.23 AM
root / root
0644
if_mzsch.txt
11.546 KB
12 Oct 2025 7.23 AM
root / root
0644
if_ole.txt
7.231 KB
12 Oct 2025 7.23 AM
root / root
0644
if_perl.txt
10.888 KB
12 Oct 2025 7.23 AM
root / root
0644
if_pyth.txt
37.055 KB
12 Oct 2025 7.23 AM
root / root
0644
if_ruby.txt
7.826 KB
12 Oct 2025 7.23 AM
root / root
0644
if_sniff.txt
0.26 KB
12 Oct 2025 7.23 AM
root / root
0644
if_tcl.txt
22.486 KB
12 Oct 2025 7.23 AM
root / root
0644
indent.txt
38.503 KB
12 Oct 2025 7.23 AM
root / root
0644
index.txt
74.651 KB
12 Oct 2025 7.23 AM
root / root
0644
insert.txt
81.207 KB
12 Oct 2025 7.23 AM
root / root
0644
intro.txt
38.307 KB
12 Oct 2025 7.23 AM
root / root
0644
map.txt
63.152 KB
12 Oct 2025 7.23 AM
root / root
0644
mbyte.txt
57.916 KB
12 Oct 2025 7.23 AM
root / root
0644
message.txt
30.498 KB
12 Oct 2025 7.23 AM
root / root
0644
mlang.txt
7.666 KB
12 Oct 2025 7.23 AM
root / root
0644
motion.txt
50.393 KB
12 Oct 2025 7.23 AM
root / root
0644
netbeans.txt
36.131 KB
12 Oct 2025 7.23 AM
root / root
0644
options.txt
378.018 KB
12 Oct 2025 7.23 AM
root / root
0644
os_390.txt
4.642 KB
12 Oct 2025 7.23 AM
root / root
0644
os_amiga.txt
5.333 KB
12 Oct 2025 7.23 AM
root / root
0644
os_beos.txt
10.726 KB
12 Oct 2025 7.23 AM
root / root
0644
os_dos.txt
11.739 KB
12 Oct 2025 7.23 AM
root / root
0644
os_mac.txt
6.69 KB
12 Oct 2025 7.23 AM
root / root
0644
os_mint.txt
1.369 KB
12 Oct 2025 7.23 AM
root / root
0644
os_msdos.txt
0.506 KB
12 Oct 2025 7.23 AM
root / root
0644
os_os2.txt
0.287 KB
12 Oct 2025 7.23 AM
root / root
0644
os_qnx.txt
3.976 KB
12 Oct 2025 7.23 AM
root / root
0644
os_risc.txt
0.315 KB
12 Oct 2025 7.23 AM
root / root
0644
os_unix.txt
2.534 KB
12 Oct 2025 7.23 AM
root / root
0644
os_vms.txt
31.348 KB
12 Oct 2025 7.23 AM
root / root
0644
os_win32.txt
13.035 KB
12 Oct 2025 7.23 AM
root / root
0644
pattern.txt
57.931 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_getscript.txt
20.584 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_gzip.txt
1.29 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_logipat.txt
4.088 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_netrw.txt
171.436 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_paren.txt
2.216 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_spec.txt
4.025 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_tar.txt
6.077 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_vimball.txt
11.575 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_zip.txt
6.87 KB
12 Oct 2025 7.23 AM
root / root
0644
print.txt
30.428 KB
12 Oct 2025 7.23 AM
root / root
0644
quickfix.txt
67.403 KB
12 Oct 2025 7.23 AM
root / root
0644
quickref.txt
69.586 KB
12 Oct 2025 7.23 AM
root / root
0644
quotes.txt
12.444 KB
12 Oct 2025 7.23 AM
root / root
0644
recover.txt
10.443 KB
12 Oct 2025 7.23 AM
root / root
0644
remote.txt
8.223 KB
12 Oct 2025 7.23 AM
root / root
0644
repeat.txt
38.646 KB
12 Oct 2025 7.23 AM
root / root
0644
rileft.txt
4.859 KB
12 Oct 2025 7.23 AM
root / root
0644
russian.txt
3.018 KB
12 Oct 2025 7.23 AM
root / root
0644
scroll.txt
13.741 KB
12 Oct 2025 7.23 AM
root / root
0644
sign.txt
6.729 KB
12 Oct 2025 7.23 AM
root / root
0644
spell.txt
61.31 KB
12 Oct 2025 7.23 AM
root / root
0644
sponsor.txt
7.029 KB
12 Oct 2025 7.23 AM
root / root
0644
starting.txt
71.896 KB
12 Oct 2025 7.23 AM
root / root
0644
syntax.txt
212.374 KB
12 Oct 2025 7.23 AM
root / root
0644
tabpage.txt
16.328 KB
12 Oct 2025 7.23 AM
root / root
0644
tags
320.952 KB
12 Oct 2025 7.23 AM
root / root
0644
tagsrch.txt
35.777 KB
12 Oct 2025 7.23 AM
root / root
0644
term.txt
44.352 KB
12 Oct 2025 7.23 AM
root / root
0644
terminal.txt
32.78 KB
12 Oct 2025 7.23 AM
root / root
0644
tips.txt
20.074 KB
12 Oct 2025 7.23 AM
root / root
0644
todo.txt
289.324 KB
12 Oct 2025 7.23 AM
root / root
0644
uganda.txt
13.695 KB
12 Oct 2025 7.23 AM
root / root
0644
undo.txt
16.151 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_01.txt
6.924 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_02.txt
23.769 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_03.txt
23.052 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_04.txt
18.635 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_05.txt
23.266 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_06.txt
9.362 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_07.txt
15.609 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_08.txt
18.92 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_09.txt
11.182 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_10.txt
28.496 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_11.txt
12.315 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_12.txt
13.109 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_20.txt
13.382 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_21.txt
17.942 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_22.txt
13.962 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_23.txt
12.293 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_24.txt
20.38 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_25.txt
18.666 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_26.txt
8.061 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_27.txt
17.308 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_28.txt
15.64 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_29.txt
19.645 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_30.txt
22.125 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_31.txt
10.15 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_32.txt
5.247 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_40.txt
22.641 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_41.txt
87.208 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_42.txt
13.475 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_43.txt
7.23 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_44.txt
28.526 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_45.txt
17.492 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_90.txt
17.247 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_toc.txt
9.002 KB
12 Oct 2025 7.23 AM
root / root
0644
various.txt
28.176 KB
12 Oct 2025 7.23 AM
root / root
0644
version4.txt
13.58 KB
12 Oct 2025 7.23 AM
root / root
0644
version5.txt
301.312 KB
12 Oct 2025 7.23 AM
root / root
0644
version6.txt
563.527 KB
12 Oct 2025 7.23 AM
root / root
0644
version7.txt
658.951 KB
12 Oct 2025 7.23 AM
root / root
0644
version8.txt
668.215 KB
12 Oct 2025 7.23 AM
root / root
0644
vi_diff.txt
41.809 KB
12 Oct 2025 7.23 AM
root / root
0644
visual.txt
21.331 KB
12 Oct 2025 7.23 AM
root / root
0644
windows.txt
51.787 KB
12 Oct 2025 7.23 AM
root / root
0644
workshop.txt
4.522 KB
12 Oct 2025 7.23 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF