I spend way too much time fumbling around because Vim doesn\'t handle closing braces like most IDEs do. Here\'s what I want to happen:
Type this:
My solution:
inoremap InsertMapForEnter()
function! InsertMapForEnter()
if pumvisible()
return "\"
elseif strcharpart(getline('.'),getpos('.')[2]-1,1) == '}'
return "\\O"
elseif strcharpart(getline('.'),getpos('.')[2]-1,2) == ''
return "\\O"
else
return "\"
endif
endfunction
Explaination:
The code above first check if you are using Enter to do confirm a code completion, if not it will indent the {|} when you type Enter. Also, it provides html tags auto indent.
Examples:
if( whatever ){|}
press Enter and you will get
if( whatever )
{
|
}
This also works for html file. See the following example
|
press Enter and you will get
|