/usr/share/vim/vim80/doc
NameSizeModeActions
arabic.txt119360644editdlrm
autocmd.txt654020644editdlrm
change.txt748770644editdlrm
channel.txt308190644editdlrm
cmdline.txt472830644editdlrm
debug.txt71820644editdlrm
debugger.txt57440644editdlrm
develop.txt223440644editdlrm
diff.txt165250644editdlrm
digraph.txt621230644editdlrm
editing.txt731760644editdlrm
eval.txt4444620644editdlrm
farsi.txt97030644editdlrm
filetype.txt266470644editdlrm
fold.txt236940644editdlrm
ft_ada.txt182470644editdlrm
ft_rust.txt95260644editdlrm
ft_sql.txt306940644editdlrm
gui.txt455920644editdlrm
gui_w32.txt189160644editdlrm
gui_x11.txt294800644editdlrm
hangulin.txt32910644editdlrm
hebrew.txt57140644editdlrm
help.txt85780644editdlrm
helphelp.txt143380644editdlrm
howto.txt29110644editdlrm
if_cscop.txt193610644editdlrm
if_lua.txt146420644editdlrm
if_mzsch.txt118230644editdlrm
if_ole.txt74050644editdlrm
if_perl.txt111490644editdlrm
if_pyth.txt379440644editdlrm
if_ruby.txt80140644editdlrm
if_sniff.txt2660644editdlrm
if_tcl.txt230260644editdlrm
indent.txt394270644editdlrm
index.txt764430644editdlrm
insert.txt831560644editdlrm
intro.txt392260644editdlrm
map.txt646680644editdlrm
mbyte.txt593060644editdlrm
message.txt312300644editdlrm
mlang.txt78500644editdlrm
motion.txt516020644editdlrm
netbeans.txt369980644editdlrm
options.txt3891160644editdlrm
os_390.txt47530644editdlrm
os_amiga.txt54610644editdlrm
os_beos.txt109830644editdlrm
os_dos.txt120210644editdlrm
os_mac.txt68510644editdlrm
os_mint.txt14020644editdlrm
os_msdos.txt5180644editdlrm
os_os2.txt2940644editdlrm
os_qnx.txt40710644editdlrm
os_risc.txt3230644editdlrm
os_unix.txt25950644editdlrm
os_vms.txt321000644editdlrm
os_win32.txt133480644editdlrm
pattern.txt593210644editdlrm
pi_getscript.txt210780644editdlrm
pi_gzip.txt13210644editdlrm
pi_logipat.txt41860644editdlrm
pi_netrw.txt1755500644editdlrm
pi_paren.txt22690644editdlrm
pi_spec.txt41220644editdlrm
pi_tar.txt62230644editdlrm
pi_vimball.txt118530644editdlrm
pi_zip.txt72290644editdlrm
print.txt311580644editdlrm
quickfix.txt690210644editdlrm
quickref.txt712560644editdlrm
quotes.txt127430644editdlrm
recover.txt106940644editdlrm
remote.txt84200644editdlrm
repeat.txt395730644editdlrm
rileft.txt49760644editdlrm
russian.txt30900644editdlrm
scroll.txt140710644editdlrm
sign.txt68910644editdlrm
spell.txt627810644editdlrm
sponsor.txt71980644editdlrm
starting.txt736220644editdlrm
syntax.txt2174710644editdlrm
tabpage.txt167200644editdlrm
tags3288320644editdlrm
tagsrch.txt366360644editdlrm
term.txt454160644editdlrm
terminal.txt335670644editdlrm
tips.txt205560644editdlrm
todo.txt2962680644editdlrm
uganda.txt140240644editdlrm
undo.txt165390644editdlrm
usr_01.txt70900644editdlrm
usr_02.txt243390644editdlrm
usr_03.txt236050644editdlrm
usr_04.txt190820644editdlrm
usr_05.txt238240644editdlrm
usr_06.txt95870644editdlrm
usr_07.txt159840644editdlrm
usr_08.txt193740644editdlrm
usr_09.txt114500644editdlrm
usr_10.txt291800644editdlrm
usr_11.txt126110644editdlrm
usr_12.txt134240644editdlrm
usr_20.txt137030644editdlrm
usr_21.txt183730644editdlrm
usr_22.txt142970644editdlrm
usr_23.txt125880644editdlrm
usr_24.txt208690644editdlrm
usr_25.txt191140644editdlrm
usr_26.txt82540644editdlrm
usr_27.txt177230644editdlrm
usr_28.txt160150644editdlrm
usr_29.txt201160644editdlrm
usr_30.txt226560644editdlrm
usr_31.txt103940644editdlrm
usr_32.txt53730644editdlrm
usr_40.txt231840644editdlrm
usr_41.txt893010644editdlrm
usr_42.txt137980644editdlrm
usr_43.txt74040644editdlrm
usr_44.txt292110644editdlrm
usr_45.txt179120644editdlrm
usr_90.txt176610644editdlrm
usr_toc.txt92180644editdlrm
various.txt288520644editdlrm
version4.txt139060644editdlrm
version5.txt3085430644editdlrm
version6.txt5770520644editdlrm
version7.txt6747660644editdlrm
version8.txt6842520644editdlrm
visual.txt218430644editdlrm
vi_diff.txt428120644editdlrm
windows.txt530300644editdlrm
workshop.txt46310644editdlrm
Edit: /usr/share/vim/vim80/doc/usr_26.txt (8254B)
*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_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 "\". 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 . 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: