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

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

问题描述

如何制作 vi - 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 answers below, 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:文件中:


In your .vimrc: 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

要查看当前设置,请执行以下操作:

To see your current settings:

: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天全站免登陆