Set Tab to 4 spaces in Vim

Source: Internet
Author: User

Set Tab to 4 spaces in Vim

It is not a problem to use tab or space for indentation, just like using four spaces in Python. This depends on your preferences. In Vim, you can easily set tabs or spaces based on different file types, and set the length to be flexible.

First, let's take a look at how to set the tab width and determine whether to use a tab or space to represent an indent:

set tabstop=4set softtabstop=4set shiftwidth=4set noexpandtab / expandtab

Note:

WheretabstopThe length of spaces displayed on a tab. The default value is 8.

softtabstopIndicates that the length of the indent is returned when you press the backspace key in the editing mode.expandtabIs particularly useful.

shiftwidthIndicates the length of each level of indentation, which is generally setsofttabstopSame.

When setexpandtabThe indentation is represented by spaces,noexpandtabA tab is used to represent an indent.

Set the tab Based on the file type:

Sometimes we want to set different tab representations for some types of files. For example, python uses four spaces to represent an indent. In our javascript conventions, we also use four spaces to represent indentation, HTML and CSS prefer to use tab labels for indentation, so you can make the following settings:

if has("autocmd")    autocmd FileType javascript setlocal ts=4 sts=4 sw=4 expandtab    autocmd FileType python setlocal ts=4 sts=4 sw=4 expandtabendif

In this way, when the opened file is.js .py, Will be indented with four spaces.

Use special symbols to represent tab characters:

In Vim, you can use special symbols to represent a tab. In this way, tabs and spaces can be easily distinguished. For example:

You can add it to vimrc:

set listset listchars=tab:▸\ ,eol:¬

Build VIM into a simple and practical IDE

Vim Learning Guide

Quick learn Vi Editor

Powerful Vim Editor

Build a Vim Development Environment on CentOS 6.2

Install the highlighted Vim editing tool in CentOS 5.4

Vim tips: C language settings

Set the Vim row number in Ubuntu

Vim editor basic tutorial

This article permanently updates the link address:

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.