Fix indentation and tabs in VIM (Vim formatting operation)

Source: Internet
Author: User

2011-03-27 wcdj

 

Let's take a look at a simple tutorial.

 

Fix indentation and tabs in VIM

Thanks to the folks in # Vim on freenode, here's a quick tutorial onHow to fix the indentation and tabs
In an XML file from within Vim...

First find out what your current settings are by typing:
: Filetype

Shocould return something like "filetype Detection: On Plugin: Off indent: Off"
1): Set filetype = xml

2): Filetype indent on

3): E

4)Gg = G

Basically what this is doing is setting the filetype to XML (so it can pickup the XML indenting rules (see: E $ vimruntime/indent
For a list of available ages
)

Then turn on indent, then reload it (: E ).

The last step is'Gg = G
'Which will acutally retab the entire file
(GG is line 1, and G is last line

).

You can find more info by reading Vim Help files:

: He gg
: He =
: He g
: He: filetype

Note: Most commands in Vim are run with by typing": Command
, You can find help by typing": Help Command
"Or simply": He cmd
". However, the main command to retab" GG = G "is not preceeded by a":"
.

 

After reading this section of tutorial, we have basically solved the problem.

 

 

 

 

Vim formatting code function -- Gg = G

 

Common functions:

(1) Gg = G is an auto-indent command (directly input in the Command state without entering a colon), GG is the first file, G is the end of the file, therefore, GG = G is used to sort out all the code.
(2) = sort rows and Add rows to sort multiple rows.
(3) Organize a code block with = {OR = I.
(4) Mg = Ng when m is not equal to N, partial indentation from m row to N row can be completed. For example, from 80 lines to 100 lines, you can use 80g = 100g, and in the command status, use: Set nu to view the row number, in general, se Nu is more accustomed to writing directly to the vim configuration file, so that the row number is displayed each time it is opened.
(5) set your own code style before writing code. Add the following command to the configuration file:
"Set indentation and row number
Set nu Ru Ai Si Ts = 4 Sw = 4
(6): Set login PRG = indent
It means to use the indent program to process the equal sign command. By default, indent is in the GNU style.
It is recommended that you do not change the code style. The Code style should be developed by yourself. = It is applicable to modifying the code or pasting the code elsewhere and then organizing the indentation.
This also shows the benefits of not using indent. If you use indent, simply formatting the code block will lose the same line First indent, and if the selected code block is not a complete internal code block, an error will occur, paste the error output to the code .... there are many drawbacks.

Refer:

Http://forum.ubuntu.org.cn/viewtopic.php? F = 35 & t = 296929 & P = 2145053

Http://blog.zol.com.cn/808/article_807892.html

Http://www.chovy.com/web-development/fix-indentation-and-tabs-in-vim/#comments

 

 

 

 

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.