How to automatically insert braces after starting a code block in vim? -
it's easy insert closing brace after typing opening one:
inoremap { {<cr>}<esc>ko
this way
if (true) {
converts to
if (true) { | }
but i'd save time , type 1 character less:
if (true)<cr>
so i'd create following rule: if return pressed , line starts if/for/while, execute {<cr>}<esc>ko
is doable?
thanks
building on previous mapping, should want:
inoremap )<cr> ) {<cr>}<esc>ko
however, should try snippet expansion plugin snipmate or ultisnips. both plugins allow define snippets placeholders , miroring (lots of them included default) expanded when <tab>
pressed after trigger.
for example, have snippet associated trigger if
expands into:
if ([condition]) { }
condition
selected, ready type, and, once done, can hit <tab>
again jump cursor between curly braces, ready type:
if (myvar == 5) { | }
this incredibly handy.
Comments
Post a Comment