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 ~