Change the indent width in Vim
To be familiar with Vim, practice is the best tutorial.
This is a HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<title>A Colorful Website</title>
<meta charset="utf-8" />
</head>
<body>
<h1 style="color: #07F">A Colorful Website</h1>
<p>This is a website about color!</p>
<h2 style="color: #C00">News</h2>
<ul>
<li>Nothing going on (yet)</li>
</ul>
<h2>Navigation</h2>
</body>
</html>
After insert some code before the </body>
:
<ul>
+ <li style="color: #F90">
+ <a href="orange.html">The Orange Page</a>
+ </li>
+ <li style="color: #00F">
+ <a href="blue.html">The Blue Page</a>
+ </li>
</ul>
</body>
</html>
Now switch to VISUAL mode, select the added code and press >>
to indent it:
<ul>
<li style="color: #F90">
<a href="orange.html">The Orange Page</a>
</li>
<li style="color: #00F">
<a href="blue.html">The Blue Page</a>
</li>
</ul>
Too many whitespace are inserted before the tag which is not what we want.
So we have to change the default indent space width in vim.
Refer to this great answer, we can append set tabstop=8 softtabstop=0 expandtab shiftwidth=2 smarttab
to ~/.vimrc
file which should be created if not exist.
Note: The mere existence of a user vimrc will change Vim’s behavior by turning off the compatible
option such as syntax highlighting.
To enable vim syntax highlighting, append syntax on
to ~/.vimrc
.
Now pressing >>
one time is to indent two whitespace.
<ul>
<li style="color: #F90">
<a href="orange.html">The Orange Page</a>
</li>
<li style="color: #00F">
<a href="blue.html">The Blue Page</a>
</li>
</ul>
本作品采用《CC 协议》,转载必须注明作者和本文链接