auto-close plugin issuse with curly brackets

回眸只為那壹抹淺笑 提交于 2019-12-24 05:46:32

问题


I am using vim from terminal as C++ IDE, and I have some issues with the autoclose curly brackets. I am using vim-autoclose plugin.

My problem is that when I am making new function and open curly brackets, the cursor doesn't return inside the function (inside the curly brackets) but it's returning at the end of the function.. Is there any way to fix that?

Also, when I am creating a new class, is there any way to automatically put a semicolon at the closing curly brackets of that class?


回答1:


Most of the autoclose plugins that I have seen does not provide the ; append part on class and struct. Hence, I don't use plugins for autoclose and added, in ~/.vimrc

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

After typing class Test, typing {; and Enter will render

class Test {
    _ //cursor here
};

and of course, indentation need to be enabled from your end, for instance by ai or cindent

Here is some more mapping, might not be relevant to vim-autoclose, that works fine on plain vim.

inoremap " ""<left>
inoremap ' ''<left>
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap {;<CR> {<CR>};<ESC>O

The last line gives

if (true) {
    _  //cursor
}

and whenever, you don't want the mapping, we need to escape it using Ctrl - v before typing the mapped char

Hope this helps




回答2:


lh-cpp mapping on { will insert the semi-colon when the key is hit while on the same line as class, enum or struct. I haven't taken the time to do something more advanced.

And in all case, the cursor goes back to in between the pair of curly brackets. If you want a newline, you'll have to hit <CR>.



来源:https://stackoverflow.com/questions/35248648/auto-close-plugin-issuse-with-curly-brackets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!