Vim-visualized operations
Vim supports the following visual operations:
V → single character selection.
V → select a row at a time.
<C-V> → block selection. It is very powerful to work with keys a and I.
GV → after exiting the visualization mode, you can use this command to automatically select the previous region in the same way.
Example:
1. General Operations
Use the preceding command to select the content to be operated, and then use other commands to perform block operations, for example: d Delete, y copy, J-row connection, <> left and right indent, = auto indent, etc.
2. delete or add script comments
In the script editing process, you sometimes need to open or comment out a block. It is too slow to edit one by one. In this case, you must perform block operations. For example, I want to comment out the following blocks.
echo
"********************************* * "
echo" there are 100
lines "
...
echo
"********************************* * "
type in Normal Mode:
<C-V> → use H or <c-d> (end line) to select the preceding content. V and V do not provide this function.
I → insert #. We found that it did not achieve the expected effect, and only inserted # in the first line #. Because it is not complete yet.
ESC → OK. Check the following results.
# Echo
"**********************************"
# Echo "there are 100
Lines"
#...
# Echo
"**********************************"
The same is true for deletion. In normal mode, type:
<C-V> → use H or <c-d> (end line) to select the preceding content. V and V do not provide this function.
D → Delete the first line #.
ESC → OK.
3. Add characters to the end of all rows
Sometimes we need to add something at the end of each line, for example, redirecting the print of the above example to a file. In normal mode, enter:
<C-V> → use $ with H or <c-d> (the end line) to select the above content. V and V do not provide this function.
A → enter the insert mode, and enter> filename.txt.
ESC → OK. Check the effect.
Echo
"**********************************"> Filename.txt
Echo "there are 100
Lines"> Filename.txt
...
Echo
"**********************************"> Filename.txt