Created
April 15, 2021 15:23
-
-
Save kuuote/436aa57e51f13a2abc24786ee52242d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s:maps = {} | |
function! HyperMap(from, to) abort | |
let key = a:from[-1:] | |
let prefix = a:from[:-2] | |
let map = get(s:maps, key, {}) | |
let s:maps[key] = map | |
let map[prefix] = {'mapto': a:to, 'eval': v:false} | |
execute 'inoremap' '<expr>' key 'HyperResolve("' .. key .. '")' | |
endfunction | |
function! HyperResolve(key) abort | |
let line = getline('.') | |
let lastidx = col('.') - 2 | |
for [map_prev, map] in items(get(s:maps, a:key, {})) | |
let prev = line[max([0, lastidx - (len(map_prev) - 1)]):col('.') - 2] | |
if prev ==# map_prev | |
return repeat("\<BS>", len(map_prev)) .. map.mapto | |
endif | |
endfor | |
return a:key | |
endfunction | |
call HyperMap('sf', '(') | |
call HyperMap('lj', ')') | |
call HyperMap('wf', '{') | |
call HyperMap('oj', '}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment