Vim tips: remove the code line number and indent the code

Source: Internet
Author: User

When you look for source code from the Internet, you will often find that the code is well formatted, but with the line number in front, copy and paste it directly to remove the line number in front to compile, and worse, with the line number in front, the code is not typographical, which is a nightmare. This problem can be easily solved in vim.

Paste a piece of code on the Internet to VIM:

Figure 1 paste the online code to VIM

Is it pretty bad? Replace it with a regular expression (First: indicates the input mode)

: % S/[\ t] * \ D \ {1, 4 \}/

Immediately get the following results:

Figure 2 result after replacement

Now the effect is quite good, but there is still a problem, the indentation is incorrect, OK.

Go to the normal mode and run the following command ):

Gg jump to the beginning of the line
V enters visual mode

G to the end of the row

= Indent selected rows (all rows are selected here)

Whether the changes are immediately visible and all code is correctly indented.

The following is the indent result:

Figure 3 final effect after indent


Vim tips: remove the code line number and indent the code

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.