问题
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