如何在vim中插入制表符(而不是空格)?

如何在vim中插入制表符(而不是空格)?,vim,indentation,vi,Vim,Indentation,Vi,我想在vim中使用制表符(而不是空格)进行缩进和特别按下时。我在互联网上查找后更改了我的.vimrc,但似乎不起作用 vimrc先生 au BufNewFile,BufRead *.py,*.pyw,*.c,*.h,*.pyx match BadWhitespace /\s\+$/ \ set tabstop=4 \ set shiftwidth=4 \ set softtabstop=4 \ set textwidth=79 \ set noexpand

我想在vim中使用制表符(而不是空格)进行缩进和特别按下
时。我在互联网上查找后更改了我的
.vimrc
,但似乎不起作用

vimrc先生

au BufNewFile,BufRead *.py,*.pyw,*.c,*.h,*.pyx match BadWhitespace /\s\+$/
    \ set tabstop=4
    \ set shiftwidth=4
    \ set softtabstop=4
    \ set textwidth=79
    \ set noexpandtab
    \ set autoindent
    \ set fileformat=unix

set encoding=utf-8
当我使用
时,会插入制表符,但在其他情况下,会插入空格而不是制表符。

您需要在每个命令之间插入
),您可以将
集合
连接在一起:

au BufNewFile,BufRead *.py,*.pyw,*.c,*.h,*.pyx match BadWhitespace /\s\+$/ |
    \ setlocal tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab autoindent
    \ textwidth=79 fileformat=unix

set encoding=utf-8
您可以使用listchars
trail
显示尾随空格:

set listchars+=trail:-

使用@Fabricator,但setexpandtab用于插入空格而不是制表符。对不起,我是用另一种方式得到的。也许你的语法错了。查看投票结果,包括这个小宝石,谢谢!“使用
时会插入选项卡。”。你的问题回答了我的问题。
setlocal
,而不是
set
@romainl。