问题描述
与white space
相比,我更喜欢使用tab
(可能与其他大多数工具有所不同)
I prefer to use tab
than white space
(may be a little different from most of others)
但是我发现,当我在行尾点击Enter
时,它将添加一些空格,但不会添加 tab .因此,我必须删除它们,然后按 tab .
But I found, when I hit Enter
at the end of line, it will add some white spaces, but not tab. So, I have to delete them and press tab.
我想知道如何将vim设置为:
I want to know how to set vim as:
- 仅使用选项卡来缩进行
- 标签页看起来像是四个空格,但实际上是标签页
- 当在行尾点击
enter
时,新行仅以制表符开头
- use only tab to indent the lines
- a tab looks like 4-spaces, but actually is a tab
- when hit
enter
at the end of a line, the new line is started with only tabs
我已经为此搜索了一段时间,但没有找到一个好的答案.预先谢谢你
I've googled for this for a while, but not found a good answer. Thank you in advance
更新
@Alok提供的答案在大多数情况下都很好.但是我只是发现,有时候,它取决于文件类型.例如,如果您正在编辑haml
文件,并且vimfiles/indent/
中有一个haml.vim
,则所有选项卡都将转换为space
.因此,如果只希望它为tab
,则应修改(或删除)相应的缩进文件.
The answer @Alok has provided works well in most of cases. But I just found, sometimes, it depends on the file type. For example, if you are editing a haml
file, and there is a haml.vim
in your vimfiles/indent/
, then all the tabs will be converted to space
. So if you want it to be tab
only, you should modify(or delete) the corresponding indent file.
推荐答案
您要查找的设置是:
set autoindent
set noexpandtab
set tabstop=4
set shiftwidth=4
单行:
set autoindent noexpandtab tabstop=4 shiftwidth=4
根据您的口味,
autoindent
可以用smartindent
或cindent
代替.还要看看filetype plugin indent on
.
autoindent
can be replaced with smartindent
or cindent
, depending upon your tastes. Also look at filetype plugin indent on
.
http://vim.wikia.com/wiki/Indenting_source_code
这篇关于如何在Vim中仅使用制表符(而不是空格)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!