Tab 键 == 4 个空格并在 Vim 中的花括号后自动缩进 [英] Tab key == 4 spaces and auto-indent after curly braces in Vim

查看:21
本文介绍了Tab 键 == 4 个空格并在 Vim 中的花括号后自动缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何制作 vi-Vim 从不使用制表符(将空格转换为制表符,糟糕!),使制表键 == 4 个空格,并在卷曲后自动缩进代码像 Emacs 那样的大括号块吗?

How do I make vi-Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks like Emacs does?

另外,我如何保存这些设置,这样我就不必再次输入它们?

Also, how do I save these settings so I never have to input them again?

我已经看到了与此相关的其他问题,但它似乎总是与我想要的有点不同.

I've seen other questions related to this, but it always seems to be a little off from what I want.

推荐答案

正如其他几个答案中所指出的,现在首选的方法不是使用 smartindent,而是使用以下方法(在您的 .vimrc):

As has been pointed out in a couple of other answers, the preferred method now is NOT to use smartindent, but instead use the following (in your .vimrc):

filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab


<打击>在你的 [.vimrc:][1] 文件中:


In your [.vimrc:][1] file:

set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

帮助文件需要一些时间来适应,但是你读得越多,Vim 就会变得越好:

The help files take a bit of time to get used to, but the more you read, the better Vim gets:

:help smartindent

更好的是,您可以将这些设置嵌入到您的源代码中以实现可移植性:

Even better, you can embed these settings in your source for portability:

:help auto-setting

要查看您当前的设置:

:set all

正如 graywh 在评论中指出的那样,smartindent 已被 cindent 取代,后者更聪明",尽管仍然主要用于具有类似 C 语法的语言:

As graywh points out in the comments, smartindent has been replaced by cindent which "Works more cleverly", although still mainly for languages with C-like syntax:

:help C-indenting

这篇关于Tab 键 == 4 个空格并在 Vim 中的花括号后自动缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆