Skip navigation.

crocodile's blog

a python lover

vim中关于tab的使用技巧

1.设定tab的位置

:set tabstop=4

2.输入tab时自动将其转化为空格

:set expandtab

如果此时需要输入真正的tab,则输入Ctrl+V, tab,在windows下是Ctrl+Q, tab

3.将已存在的tab都转化为空格

:retab

4.设定编辑模式下tab的视在宽度

:set softtabstop

这不改变tabstop,但让编辑的时候tab看起来是指定的宽度,输入tab时会插入的tab和空格的混合,比如tabstop=4,softtabstop=10,那么插入tab时会将光标移动10个字符,可能会是两个tab加两个空格,这对backspace也有效。

5.解决shiftwidth和tabstop不等时的麻烦

:set smarttab

在行首输入tab时插入宽度为shiftwidth的空白,在其他地方按tabstop和softtabstop处理

6.将tab显示为可见字符

:set list listchars=tab:>-

tab将被显示为>—-的形式

7.只在编辑特定类型的文件时展开tab

将如下代码加入~/.vimrc

autocmd FileType * set tabstop=4|set shiftwidth=4|set noexpandtab
autocmd FileType python set tabstop=4|set shiftwidth=4|set expandtab

参考文章:

1. VIM Tip#12
2. :help tabstop

High Performance MySQL–第二章VIM使用技巧(随时补充中)

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

Type the two words displayed in the image below:


Smilies

July 2009
S M T W T F S
June 2009August 2009
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31