Skip to content

Instantly share code, notes, and snippets.

@DeaR DeaR/super_map.vim
Last active Dec 17, 2015

Embed
What would you like to do?
" call g:super_map('n', '<buffer>', "\<Space>uol", ":Unite outline -no-quit\<CR>")
" 2nd args: <buffer>, <expr>, <silent>, <unique>
let s:super_map_buf = {
\ 'n' : {}, 'x' : {}, 's' : {}, 'o' : {},
\ 'i' : {}, 'c' : {}, 'l' : {}}
function! s:super_map_do(char, mode)
let key = a:char
while(1)
echo key
if has_key(s:super_map_buf[a:mode], key)
if s:super_map_buf[a:mode][key][0] =~ '<expr>'
return eval(s:super_map_buf[a:mode][key][1])
else
return s:super_map_buf[a:mode][key][1]
endif
elseif empty(filter(copy(s:super_map_buf[a:mode]), '
\ v:key =~# ("\\V\\^" . escape(key, "\\"))'))
echo key 'is undefined.'
return
endif
let key .= nr2char(getchar())
endwhile
endfunction
function! g:super_map(mode, opt, lhs, rhs)
let char = matchstr(a:lhs, '^.')
for m in split(a:mode, '\zs')
call extend(
\ s:super_map_buf[m],
\ {a:lhs : [a:opt, a:rhs]},
\ a:opt =~ '<unique>' ? 'error' : 'force')
execute
\ m . 'map'
\ substitute(a:opt, '<expr>', '', '') . '<expr>'
\ substitute(char, ' ', "<Space>", '')
\ '<SID>super_map_do("' . char . '", "' . m . '")'
endfor
endfunction
function! g:super_noremap(mode, opt, lhs, rhs)
let char = matchstr(a:lhs, '^.')
for m in split(a:mode, '\zs')
call extend(
\ s:super_map_buf[m],
\ {a:lhs : [a:opt, a:rhs]},
\ a:opt =~ '<unique>' ? 'error' : 'force')
execute
\ m . 'noremap'
\ substitute(a:opt, '<expr>', '', '') . '<expr>'
\ substitute(char, ' ', "<Space>", '')
\ '<SID>super_map_do("' . char . '", "' . m . '")'
endfor
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.