Vim自动缩进换行符 [英] Vim Auto Indent with newline

查看:195
本文介绍了Vim自动缩进换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使vim将光标放在大括号内,从新行开始,即使用| |.表示光标位置:

How do I get vim to place the cursor within the braces starting on a new line, ie with | denoting the cursor position :

class {
  |
}

现在使用我的设置,它只能执行此操作

right now with my settings it only does this

class {
|}

我在.vimrc文件中得到了这个 设置autoindent shiftwidth = 2 tabstop = 2 noexpandtab

I got this in my .vimrc file set autoindent shiftwidth=2 tabstop=2 noexpandtab

基本上,我只想普通的IDE对其进行缩进.

Basically I just want how a normal IDE would indent it.

更新:

我发现了如何使用inoremap { {<CR>}<Esc>O

推荐答案

将其放在您的.vimrc中:

Put this in your .vimrc :

imap <C-Return> <CR><CR><C-o>k<Tab>

假设autoindentsmartindent的设置正确,在括号之间键入Ctrl + Return会将光标放在想要的位置.

Assuming autoindent and smartindent are set correctly, typing Ctrl + Return between braces will put your cursor where you want it to be.

这篇关于Vim自动缩进换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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