The plugin lexima.vim provides smart behaviour when entering an opening expression, pressing <backspace>
or <CR>
.
By default rules e.g. for (,[,{
exist. However, someone else has written a few rules for html/xml and template languages such as jinja and has published them in a separate github repository under the title lexima-template-rules:
https://github.com/deathlyfrantic/lexima-template-rules
The relevant rules are described as following:
Before Input After
----------------------------------------------------------------------------
| < <|>
----------------------------------------------------------------------------
<|> or <|/> <Backspace> |
----------------------------------------------------------------------------
<tag>| or <tag/>| <Backspace> <tag|> or <tag|/>
----------------------------------------------------------------------------
<tag foo="bar"|> / <tag foo="bar"/>|
----------------------------------------------------------------------------
<tag|/> / <tag/>|
----------------------------------------------------------------------------
<tag>|</tag> <Enter> <tag>
|
</tag>
----------------------------------------------------------------------------
Together with the mapping already used by OP using inoremap
❯ cat ~/.vim/vimrc
source $VIMRUNTIME/defaults.vim
inoremap <silent> <C-c> </<C-X><C-O><C-X><Esc>F<i
You would type <body><C-c><CR>
.
<C-c>
in insert mode has a subtle, but potentially useful default behavior that you may not want to overwrite.