我如何使vi-Vim从来不使用制表符(将空格转换为制表符,坏!),使制表键== 4个空格,并自动缩进代码花括号块后像Emacs ?
此外,我如何保存这些设置,这样我就不必再次输入它们了?
我见过其他与此相关的问题,但它似乎总是有点偏离我想要的。
我如何使vi-Vim从来不使用制表符(将空格转换为制表符,坏!),使制表键== 4个空格,并自动缩进代码花括号块后像Emacs ?
此外,我如何保存这些设置,这样我就不必再次输入它们了?
我见过其他与此相关的问题,但它似乎总是有点偏离我想要的。
当前回答
相关的,如果你打开一个同时使用制表符和空格的文件,假设你有
set expandtab ts=4 sw=4 ai
可以将整个文件中的所有制表符替换为空格
:%retab
其他回答
在许多Linux系统上,如Ubuntu,默认情况下.vimrc文件不存在,因此建议您先创建它。
不要使用主目录中存在的.viminfo文件。它有不同的用途。
步骤1:进入主目录
cd ~
步骤2:创建文件
vim . vimrc
步骤3:添加上述配置
filetype plugin indent on
set tabstop=4
set shiftwidth=4
set expandtab
第三步:保存文件,按Shift + ZZ键。
编辑~/.vimrc
$ vim ~/.vimrc
增加如下行:
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
毕竟,您可以编辑.vimrc,然后添加conf
set tabstop=4
或者执行命令
推荐的方法是使用基于文件类型的缩进,如果不能满足要求,只使用smartindent和cindent。
将以下内容添加到.vimrc中
set expandtab
set shiftwidth=2
set softtabstop=2
filetype plugin indent on
希望这是一个不同的答案。
要在大多数文件中使用4个空格的制表符,在Makefiles中使用真正的8宽制表符字符,并在包括C/ c++在内的各种文件中使用自动缩进,请将此放在~/中。vimrc文件:
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Use filetype detection and file-based automatic indenting.
filetype plugin indent on
" Use actual tab chars in Makefiles.
autocmd FileType make set tabstop=8 shiftwidth=8 softtabstop=0 noexpandtab
endif
" For everything else, use a tab width of 4 space chars.
set tabstop=4 " The width of a TAB is set to 4.
" Still it is a \t. It is just that
" Vim will interpret it to be having
" a width of 4.
set shiftwidth=4 " Indents will have a width of 4.
set softtabstop=4 " Sets the number of columns for a TAB.
set expandtab " Expand TABs to spaces.