使用成对自动关闭时如何在Vim中设置自动插入新行并缩进 [英] How to set auto insert new line and indent in Vim when use the auto close in pair

查看:238
本文介绍了使用成对自动关闭时如何在Vim中设置自动插入新行并缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个名为 vim-autoclose 的Vim自动配对插件.就像其他IDE一样,它的效果很好.例如,当您键入{时,它会为您提供{|}("|"代表光标).然后,如果按"Enter",{|}变为:

I found a Vim auto pair plugin called vim-autoclose. It works great just like other IDEs. For example, when you type { it gives you {|} (the "|" represents the cursor). Then, if you press "Enter", the {|} becomes:

{

      |

}

这是我所需要的,但不幸的是,它禁用了我的中文输入法应用程序,因此我不得不放弃它.

This is what I need, but unfortunately it disables my Chinese input method application,so I have to abandon it.

我尝试了其他自动关闭插件,但是它们都无法以这种方式自动关闭.我找到了一种使自动关闭工作像上面一样的方法.

I have tried other autoclose plugins, but none of them can auto close in this way. I found a way to make auto close work like the way above.

:autocmd FileType c,java,javascript ino <buffer> { <C-G>u{<CR>}<Esc>O<C-T>

但是它的shiftwidth有问题.例如,如果我:set shiftwidth=4,在{}之间的新行将有8个空格缩进.新行中的缩进使shiftwidth加倍.

But it has a problem with the shiftwidth. For example, if I :set shiftwidth=4 the new line between {} will have an 8 space indent. The indent in the new line doubles the shiftwidth.

我的问题是如何将新行的缩进设置为shiftwidth的相同空格缩进?

My question is how to set the indent of the new line to the same space indent of shiftwidth?

推荐答案

在vimrc中设置set aiset smartindent

After setting set ai and set smartindent in vimrc

使用以下内容

inoremap {<CR> {<CR>}<ESC>O

应该工作.最后一个字符是capital O,而不是零.

should work. The last character is capital O, not zero.

这篇关于使用成对自动关闭时如何在Vim中设置自动插入新行并缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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