Vim tab is set to 4 spaces

Source: Internet
Author: User

For vim to better support Python to write code, modify the tab default 4 spaces There are two ways to set up:

1. VIM/ETC/VIMRC

1 setts=4
2 setsw=4

2. VIM/ETC/VIMRC

1 setts=4
2 setexpandtab
3 setautoindent
The second is recommended, which results in 4 spaces when you press the TAB key, which has the best compatibility. Set Tab in Vim

Indentation tab or space, this is not a problem, just like python with four spaces to indent, this is to see a person's preferences. In Vim, it is convenient to set the Tab tab or space according to different file types, and also to set the length, which is very flexible.

First, let's see how to set the tab width and how to determine whether to use Tab tab or empty Glyd to represent an indentation:

Set tabstop=4
Set softtabstop=4
Set shiftwidth=4
Set Noexpandtab/expandtab Description:

Which tabstop represents the length of how many spaces a tab displays, default 8.

softtabstopIndicates that the length of the indent is returned when you press the BACKSPACE bar while in edit mode, expandtab especially useful when used.

shiftwidthIndicates the length of each level of indentation, generally set to the softtabstop same.

When set expandtab to, indentation is represented by an empty glyd, and noexpandtab a tab is used to denote an indentation.

To set tab according to file type:

Sometimes you want to set different tab performance for certain types of files, such as Python with four empty glyd for an indentation, and four null glyd for indentation in our JavaScript conventions, and HTML and CSS like tab tabs to indent, so you can do the following:

If has ("Autocmd")
Autocmd FileType javascript setlocal ts=4 sts=4 sw=4 expandtab
Autocmd FileType python setlocal ts=4 sts=4 sw=4 expandtab
endif

So when the file is .js .py opened, it will be indented with four spaces.

So found that after the tab is not four spaces, is a tab, I need to press TAB instead of four spacebar, so remove sts=4, fix

To represent tab tabs with special symbols:

In Vim, you can use special symbols to represent a tab tab so that tab tabs and spaces can easily be distinguished, such as:

To join in VIMRC:

Set list
Set listchars=tab:?\, EOL:? Reference: http://blog.sina.com.cn/s/blog_620ccfbf01010erz.html

Vim tab is set to 4 spaces

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.