Vim and padding with parentheses / brackets

When editing JavaScript, I usually have to do this:

function myFunc() { // func body here } 

I tried several closing plugins, such as AutoClose and vrackets, but when I came to the code as shown above, they all do it:

 function myFunc() {<CR> |} 

How can I get Vim to insert a in front of the bracket when I jump to a new line and draw the cursor correctly like this:

 function myFunc() {<CR> |<CR> } 

Is there a plugin or something that does this?

+6
source share
5 answers

I have this line in my ~/.vimrc :

 inoremap <C-Return> <CR><CR><Co>k<Tab> 
+2
source

I use this mapping in conjunction with AutoClose:

 inoremap {<CR> {<CR>}<Co>O 

No special key combination is required.

+6
source

I may have left the base, but have you tried using the shortened command?

 :ab {} {<cr>}<esc>ko 

Of course, I have a smartindent, and I would have to enter {} to complete it, but this works for me.

+1
source

Auto Pairs does just that.

+1
source

Have you tried matching the entire function, e.g.

inoremap ,4 function() {}<left><enter><esc>O

0
source

Source: https://habr.com/ru/post/910259/


All Articles