Skip to content

Instantly share code, notes, and snippets.

@DeaR
Last active December 17, 2015 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeaR/5581889 to your computer and use it in GitHub Desktop.
Save DeaR/5581889 to your computer and use it in GitHub Desktop.
" 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