Change the default tab of VIM to 4 spaces.

Source: Internet
Author: User

Scenario:

When writing a Python script using vim, the default tab is inconvenient because python is strictly aligned with spaces. We can change the vim configuration file to four spaces when writing a Python script.

Supplement:

You can learn everything you want through the vim manual. If my description is not very clear, you can get help.

Open the help of VIM: Help

You can find this article in the set your settings section.

1. First modify ~ /. Vimrc

Add:

Filetype plugin on "add Vim support for file types

In this way, VIM can automatically detect the file type when opening the file.

2. Create a python-specific configuration file

Vim is powerful. You can configure Vim to load different configuration files based on the file opened.

Here we need to compile a configuration file that supports the Python language.

I use Ubuntu 10.1 Vim 7.3

Python is supported by default.

CD/usr/share/Vim/vim73

Find-name python. Vim

/Usr/share/Vim/vim73/ftplugin/python. Vim

Copy the configuration file ~ /. Vim/ftplugin/. If this directory is not available, create

CP/usr/share/Vim/vim73/ftplugin/python. Vim ~ /. Vim/ftplugin/

In this way, when you load the. py file, VIM will go back and load the settings in Python. vim.

3. By default, the tab is not set in Python. vim.

Therefore, you only need to add

"Use 4 space for indent

Setlocal et sta Sw = 4 STS = 4

Bytes --------------------------------------------------------------------------------------------------------

Command explanation

Et Expandtab, which expands the tab key into spaces.
Sta Smartab. press tab at the beginning of the row to add SW spaces.
SW Shiftwidth, number of spaces inserted in the auto indent
STS Softabstop: Use <tab> or <BS> to automatically insert or delete spaces.

Then we will make it a success ~

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.