0

I am a new vim user and I try to play around a bit. I am trying to have an efficient way to code a block with figure brackets :

{
    blabla;
    ....
    blabla;
}

So the first thing I did is put the following in my .vimrc to get the opening and closing bracket when I write a opening bracket :

noremap <silent> <C-S>          :update<CR>
vnoremap <silent> <C-S>         <C-C>:update<CR>
inoremap <silent> <C-S>         <C-O>:update<CR>

And to start writing within the brackets, I then hit : "i" "enter" "enter" "esc" "ciw"

Seems a bit tedious, what do you think?

roi_saumon
  • 489
  • 4
  • 13

2 Answers2

2

There was already another thread on this topic: Automatic closing brackets for Vim

Alternatively, you can try out a plugin, such as: delimitMate

chrboesch
  • 171
  • 1
  • 6
1

inoremap { {}<Left>:
To open a closing } right after the cursor

inoremap { {<cr>}<c-o>O
To open a closing } below the cursor. Maybe you want to set autoindent to.

Tinmarino
  • 3,693
  • 24
  • 33
  • Thanks tinmarino. How do you put an indent in there? Is it good practice to use this remap? – roi_saumon Jan 27 '18 at 21:55
  • It's not a **bad** practice but you will have to maintain it so prefer using a plugin. I personally get my indent via the plugin pymode. Because the nesting level is different in python. See for the ad hoc plugin for your language. In Xml for autoindent you may want set autoindent (read the help) + add 4 spaces in the map `inoremap { {}O ` (4 spaces at the end [not easy to show in md]) – Tinmarino Jan 28 '18 at 15:32