- The repetition of VIM techniques
- Type of vim repetition
- Duplicate text changes
- In-line Find duplicates
- Full-text lookup duplicates
- Text repeat substitution
- Duplicate macro Recording
The repetition of VIM techniques
When we vim
edit the text, we will inevitably do some repetitive operation, when we want to repeat the last operation, do we have to repeat the same operation? This will inevitably waste time. Then vim
you recorded some of the last operations in vim
the register, when you want to repeat the last operation, click the shortcut key directly.
Type of vim repetition
There are five basic types of repetition in vim, namely:
Repeating type |
repeating operator | Fallback
operator |
Duplicate text changes |
. |
U |
In-line Find duplicates |
; |
, |
Full-text lookup duplicates |
N |
N |
Text substitution repetition |
& |
U |
Macro Repetition |
@[Register] |
U |
Let's see a detailed description of these repeated operations
Duplicate text changes
: h .
Check out the Help manual for Vim by:
.
Repeat, with Count replaced with [count]. Also repeat a Yank command, when the ' Y ' flag was included in ' Cpoptions '. Does not repeat a command-line command.
.
the visible action is used to repeat the last change
give some chestnuts :
example1:
Use x
the action to delete a character, followed by a .
repeat delete character
example2:
Delete dd
a row of data, and then .
delete a row of data by repeating it
Example3:
yy
copy a row of data, p
paste, click .
to repeat the paste operation
In-line Find duplicates
Sometimes we want to find a character in the current row, we can find it either f{char}/t{char}
from the current position to the end of the line, or by starting at the beginning of the current F{char}/T{char}
position. The simple is to find the lower case backwards, capitalize forward.
: h ;
Check out the Help manual for Vim by:
;
Repeat latest F, T, F or t [count] times. See Cpo-;
,
Repeat latest F, T, F or T in opposite direction [count] times. See also cpo-;
We can use it ;
to repeat the operation of VIM lookup and ,
repeat the reverse search.
Give some chestnuts:
example1:
In the main.cc
31 lines of the file, first use f:
to find the :
characters, then use ;
to repeat the find operation
example2:
We will repeat the change operation described earlier and the inline lookup operation repeatedly, in the main.cc
31 lines of the file f+:
to find the first :
character, and then replace the characters with cl
:
+
characters, followed by repeated typing ;.
To :
replace +
the rest with
Full-text lookup duplicates
:h /
to view vim
the Help manual:
/{pattern}[/]<CR>
Search forward for the [count] ' th occurrence of {pattern} exclusive.
?{pattern}[?]<CR>
Search backward for the [count] ' th previous occurrence of {pattern} exclusive.
vim
/pattern<CR>
to find a match in the full text from the current position, or ?pattern<CR>
to start looking up a match in the full text from the current position.
:h n
to view vim
the Help manual:
n
Repeat the latest "/" or "?" [Count] times. Last-pattern {Vi:no Count}
N
Repeat the latest "/" or "?" [Count] times in opposite direction. Last-pattern {Vi:no Count}
After the search is complete, we can jump to the previous match by n
jumping to the next match N
give me a chestnut:
main.cc
look inside suite
and capitalize the gUaw
word, then repeat n.
to capitalize
Text repeat substitution
:h &
to view vim
the Help manual:
&
Synonym For:s (repeat last substitute). Note that the flags is not a remembered, thus it might actually work differently. You can use:&& to keep the flags.
In general, we can use this form :s/target/replacement/g
to replace the string that appears in the row with target
another string replacement
, and if we want to perform the same substitution work on another line, we can &
repeat the substitution operation
give me a chestnut:
main.cc
Replace the string in the file 31 line with the ::
following form +-+
: s/::/+-+/g
, and then j&
replace the following two lines with a repeat operation
Duplicate macro Recording
:h @
to view vim
the Help manual:
@{0-9a-z".=*+}
Execute the contents of register {0-9a-z ". =*+} [Count] times. Note that register's '% ' (name of the current file) and ' # ' (Name of the alternate file) cannot is used.
vim
Inside the macro recording is a very NB function, you can record a series of operations into the register, and then directly @{寄存器}
can repeat the previously recorded series of operations
vim
It can be used q{寄存器}
to start recording, then use q
to end the recording, any of the name of the register, a-z
such as qa
recording the operation into the register, and a
then if you want to use the macro, you @a
can repeat the recording operation
Give some chestnuts:
example1: Replace the current line with ::
+-+
, then delete the number at the end of the line ;
and indent the text one line to the right
example2: in the content for this is number1
copy, then paste to the next line, and add the number 1
to 2
, the content becomes this is number2
, so repeat 10 times, so the last line of content should be this is number12
Here is vim
a cold knowledge of the inside, that is Ctrl+a
, the operation will start from the cursor, looking backwards from the cursor nearest number, if found on the number of the value of 1, the same Ctrl+x
is the number minus 1, so we recorded such a macro operation qa
, yy
,,,, and p
ctrl+a
q
then [email protected]
Repeat this macro 10 times is the effect of the above
The repetition of VIM techniques