Vim-visualized operations

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.