mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 17:40:06 +08:00
Merge branch 'mapping' into dev
This commit is contained in:
commit
4a49c367a2
27
autoload/SpaceVim/api/vim/compatible.vim
Normal file
27
autoload/SpaceVim/api/vim/compatible.vim
Normal file
@ -0,0 +1,27 @@
|
||||
function! SpaceVim#api#vim#compatible#get() abort
|
||||
return map({
|
||||
\ 'execute' : '',
|
||||
\ },
|
||||
\ "function('s:' . v:key)"
|
||||
\ )
|
||||
endfunction
|
||||
|
||||
function! s:execute(cmd, ...) abort
|
||||
if a:0 == 0
|
||||
let s = 'silent'
|
||||
else
|
||||
let s = a:1
|
||||
endif
|
||||
redir => output
|
||||
if s ==# 'silent'
|
||||
silent execute a:cmd
|
||||
elseif s ==# 'silent!'
|
||||
silent! execute a:cmd
|
||||
else
|
||||
execute a:cmd
|
||||
endif
|
||||
redir END
|
||||
return output
|
||||
endfunction
|
||||
|
||||
" vim:set et sw=2 cc=80:
|
35
autoload/SpaceVim/api/vim/mapping.vim
Normal file
35
autoload/SpaceVim/api/vim/mapping.vim
Normal file
@ -0,0 +1,35 @@
|
||||
let s:VIM = SpaceVim#api#import('vim#compatible')
|
||||
|
||||
function! SpaceVim#api#vim#mapping#get() abort
|
||||
return map({
|
||||
\ 'map' : '',
|
||||
\ },
|
||||
\ "function('s:' . v:key)"
|
||||
\ )
|
||||
endfunction
|
||||
|
||||
function! s:map(...) abort
|
||||
if a:0 == 1
|
||||
return s:parser(s:VIM.execute(':map ' . a:1))
|
||||
endif
|
||||
return []
|
||||
endfunction
|
||||
|
||||
function! s:parser(rst) abort
|
||||
let mappings = split(a:rst, "\n")
|
||||
let mappings = map(mappings, 'split(v:val)')
|
||||
let rst = []
|
||||
for mapping in mappings
|
||||
if len(mapping) >= 3
|
||||
let mode = mapping[0]
|
||||
let key = mapping[1]
|
||||
let m = maparg(key, mode, 0, 1)
|
||||
if !empty(m)
|
||||
call add(rst, m)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
return rst
|
||||
endfunction
|
||||
|
||||
" vim:set et sw=2 cc=80:
|
Loading…
Reference in New Issue
Block a user