How to insert the specified string at the beginning or end of each line in Vi/vim

Source: Internet
Author: User

Header:%s/^/your_word/

End of Line:%s/$/your_word/

Key operation:
Note: Ctrl + V enters column edit mode, moves the cursor down or up, marks the beginning of the line that needs comment, then presses the uppercase I, then inserts the comment, such as "#", and then presses ESC, which is all commented.
Delete: Press v First, enter visual mode, select the number of columns in the landscape (such as "#" comment symbol, need to select two columns), then press ESC, then press CTRL + V to enter the column editing mode, move the cursor down or up, select the comment section, and then press D to delete the note symbol (#).

PS: Of course, it is not necessarily the shell's annotation "#", it can be "//", or any other character; Vim does not know what is an annotation, all characters.

Use the Replace command:
Add a/F comment at the beginning of the entire content
:% s/^/\/\//g
Add a/F comment at the beginning of 2~50
:2,50 s/^/\/\//g
Delete//number at the beginning of 2~50
:2,50 s/^\/\///g

How to insert the specified string at the beginning or end of each line in Vi/vim

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.