Settings for function keys and configuration files for vim indentation

Source: Internet
Author: User

When you are programming with VIM, you often need to indent your code to increase the readability of your programs and to maintain your code later.

The purpose of indentation can be achieved in a number of ways:

1) Command mode

2) Visual mode

2) input modes (entry mode)

3) last line (Last-line mode)

4) in/ETC/VIMRC has given vim the environment configuration, generally, personalized custom vim function,

It is recommended to configure it in the ~/.VIMRC file (the file can be created by the user in general).

Command mode:

>> the current line increments by one unit indent (that is, how many spaces are one unit, the value of the profile parameter shiftwidth)
<< Decrease one unit indent for the current row (multiple units can be indented several times in a row)
#>> the current line adds # units indent
#<< Current Line Reduced # units indent (6>>)

= = for automatic typesetting, can also reduce a unit indent

Visual mode: (in command mode v toggle)

The selected single or multiple lines can be:

> Add a unit indent

< reduction of one unit indent

#> Increase # Unit indent

#< Decrease # Unit Indent

Input mode:

ctrl+t Add a unit indent

ctrl+d Decrease one unit indent

Last-line mode:

Startline, endline > Add a unit indent from Startline to EndLine (proven, cannot appear #>)

Startline, endline < reduce the startline to endline by one unit indent

To add a personalized auto-indent environment configuration parameter in profile ~/.VIMRC:

There are generally the following types:

Autoindent: The newly added row and the previous row have the same indentation form;

SMARTINDENT:1) Each row has the same indentation as the previous line;
2) When the right curly brace "}" is encountered, the indentation form is canceled;
3) If a line begins with #, it is not indented;
4) also added the ability to identify C language keywords;

Cindent: This is the C language indentation form, the use of such indentation method of programming language: C,c++,java, etc.;
When this indentation format is used, VI will automatically adopt the standard C language form.

Advanced: Autoindent < Smartindent < cindent

You can use the following command to indent the settings: (Can be manipulated in the last row mode)
Set autoindent or set AI
Set smartindent or Set Si
Set cindent or Set CI

When indenting is off: set noautoindent

...

Parameters related to indentation (indent) are: Shiftwidth, TabStop, Softtabstop, Expandtab.

Shiftwidth Operations (<< and >>) are indented in one unit;
TabStop the number of spaces that a TAB key occupies, the Linux kernel code suggests that each tab occupy 8 spaces;
Softtabstop the number of spaces actually occupied when the TAB key is typed;
Expandtab the Input tab automatically converts it to a space;

Describes the relationship between TabStop, Softtabstop, and Expandtab:

1) All three are used to define the number of spaces represented by the TAB key at a time;
2) When Softtabstop is defined, both TabStop and Expandtab are subject to softtabstop;
3) that is, when softtabstop=4 regardless of tabstop and Expandtab, the final value is 4 spaces as a unit.

Vim ~/.VIMRC

Settings for function keys and configuration files for vim indentation

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.