Working on a more lightweight vim-endwise replacement (endwise breaks imap <expr> <CR>
mappings).
In the following text:
def name<-cursor here
it adds a newline and another line with an end
:
def name
<-cursor here
end
This mapping does the job:
autocmd FileType ruby inoremap <buffer> <expr> <CR> match(getline('.'), 'def') >= 0 ? '<CR><CR>end<Esc>-cc' : '<CR>'
However, I'd like to extend this to also understand if
, case
and do
, but the following does not work:
autocmd FileType ruby inoremap <buffer> <expr> <CR> match(getline('.'), 'def\|if\|case\|do') >= 0 ? '<CR><CR>end<Esc>-cc' : '<CR>'
Even though match(" case abc", 'def\|if\|case\|do') >= 0
returns 1 (e.g. true).
What am I doing wrong?
'\<CR>'
returns text, not a newline, an unescaped'<CR>'
errors out, even thoughmatch
seems to work properly.|
'<CR>'
does not work, nor'\<CR>'
does, I've seen people use""<CR'
and'\<lt>CR>'
, but none of them worked in a function. I'm pretty satisfied with my current solution, will dig deeper when I decide I need to add a closing curly brace when I open one and press CR.