Vim tab settings (2): Use autocmd to apply different tab settings for different file types

Source: Internet
Author: User

The last time we talked about how to configure tabs/spaces in vim. Recently, many web pages are written. You do not want to replace the tab when editing HTML, and one tab occupies two spaces. You still need to use four spaces when editing other files. Finally, we found this method:

 

In. vimrc:

Autocmd bufnewfile, bufread *. html, *. htm, *. CSS, *. js set noexpandtab tabstop = 2 shiftwidth = 2

Autocmd is an "Automatic Command" that is automatically executed in the event of certain events, similar to the hook function.

 

Bufnewfile indicates that when you edit a file that does not exist

 

When bufread reads an existing file

 

The following is the file name pattern (separated by,) and the command to be executed. To execute multiple commands, use | to separate them.

 

Links:
Vim reference: autocmd: http://man.chinaunix.net/newsoft/vi/doc/autocmd.html

 

Related logs:
Vim tab settings: http://blog.csdn.net/shell_picker/archive/2010/11/24/6033023.aspx

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.