[Linux] How to indent the space in Vim to tab indent __linux

Source: Internet
Author: User

Some students like to use space to do indentation. So a lot of code start at the beginning with a continuous repeating space, some are four spaces, some even eight spaces. Uncle can not endure aunt.

Vim has some retab options for indenting all vim-processed documents, but that's barbaric, and we're not going to let vim automatically process all the files.


So the more appropriate way to do this is by hand. You can use the following commands in VIM:


:%s/    /\t/g  

Explain:

The first colon is the beginning of the command that must be executed in vim. Just like '/' is the beginning of the lookup command.

% means to operate on each row

s represents replacement

The first '/' represents the content to be replaced (here are four consecutive spaces)

The second '/' means what to replace (here is ' \ t ' is tab)

The third '/' indicates the option of substitution ('/g ' indicates an entire row substitution, '/& ' replaces only the first occurrence of the line)

In Vim inside use ': Help:s ' can see detailed explanation

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.