How to modify the Tab in the VIM editor to 4 spaces

  

The most commonly used editor for Linux users is the VIM editor. In order to improve our editing speed, we often set some shortcuts in the editor. Today, Xiaobian will share with you the method of setting the Tab key to 4 spaces in the VIM editor.

Setting method:

Edit

vim ~ /.vimrc

The new file does not exist, the file already exists, an additional tail < Br>

Add

“ This code will only be executed if autocommands is supported.

if has(”autocmd“)

” Using file type checking and file-based auto-shrinking

filetype plugin indent on

&ldquo The length of the tab in the Makefiles file is 8.

autocmd FileType make set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab

endif

” For other cases, use 4 Space width TAB

set tabstop=4 “ The width of the TAB is set to 4 spaces.

” But still \\t. Just vim interprets it as 4 spaces wide, with other editors or \\t symbols

“ Vim will interpret it to be having< Br>

” a width of 4.

set shiftwidth=4 “ Indent using a width of 4 spaces.

set softtabstop=4 ” Set the number of columns occupied by the tab. When entering tab, set the width of 4 spaces.

set expandtab “ The extension tab is a space.

vim temporarily turns off indentation and annotation auto-indentation settings

VIM will automatically indent when pasting code, making the code messy, maybe even because of a comment on a line The following code is all commented out,

Method 1

set pastetoggle

to turn off automatic indentation

or set as a shortcut, the most convenient The method is to add a sentence to the .vimrc:

set pastetoggle=“F9”

In the insert mode, just press the F9 key to switch the automatic indent.

When you need to write your own code, enter the insert mode, the default is automatically indented.

Method 2

set paste

Then enter the insert mode paste, the code will not be automatically indented.

When you type the code, you need to automatically indent it. You need to change it back:

set nopaste

This is how to set the Tab key to 4 spaces in the VIM editor. Users who need to use the VIM editor frequently will set it up, which will improve your editing speed.

Copyright © Windows knowledge All Rights Reserved