1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 13:50:05 +08:00

feat(leader): add custom leader function

close https://github.com/SpaceVim/SpaceVim/issues/3611
This commit is contained in:
wsdjeg 2022-10-24 22:24:51 +08:00
parent 71bc539267
commit 7c656469bf
4 changed files with 56 additions and 5 deletions

View File

@ -1353,6 +1353,8 @@ let g:spacevim_wildignore
let g:_spacevim_mappings = {}
let g:_spacevim_mappings_space_custom = []
let g:_spacevim_mappings_space_custom_group_name = []
let g:_spacevim_mappings_leader_custom = []
let g:_spacevim_mappings_leader_custom_group_name = []
let g:_spacevim_mappings_language_specified_space_custom = {}
let g:_spacevim_mappings_lang_group_name = {}
let g:_spacevim_neobundle_installed = 0

View File

@ -140,8 +140,7 @@ function! s:fix_colorschem_in_SpaceVim() abort
hi SpaceVimLeaderGuiderGroupName cterm=bold ctermfg=175 gui=bold guifg=#d3869b
endfunction
function! SpaceVim#autocmds#VimEnter() abort
call SpaceVim#api#import('vim#highlight').hide_in_normal('EndOfBuffer')
function! s:apply_custom_space_keybindings() abort
for argv in g:_spacevim_mappings_space_custom_group_name
if len(argv[0]) == 1
if !has_key(g:_spacevim_mappings_space, argv[0][0])
@ -162,6 +161,36 @@ function! SpaceVim#autocmds#VimEnter() abort
for argv in g:_spacevim_mappings_space_custom
call call('SpaceVim#mapping#space#def', argv)
endfor
endfunction
function! s:apply_custom_leader_keybindings() abort
for argv in g:_spacevim_mappings_leader_custom_group_name
if len(argv[0]) == 1
if !has_key(g:_spacevim_mappings, argv[0][0])
let g:_spacevim_mappings[argv[0][0]] = {'name' : argv[1]}
endif
elseif len(argv[0]) == 2
if !has_key(g:_spacevim_mappings, argv[0][0])
let g:_spacevim_mappings[argv[0][0]] = {'name' : '+Unnamed',
\ argv[0][1] : { 'name' : argv[1]},
\ }
else
if !has_key(g:_spacevim_mappings[argv[0][0]], argv[0][1])
let g:_spacevim_mappings[argv[0][0]][argv[0][1]] = {'name' : argv[1]}
endif
endif
endif
endfor
for argv in g:_spacevim_mappings_leader_custom
call call('SpaceVim#mapping#def', argv)
endfor
endfunction
function! SpaceVim#autocmds#VimEnter() abort
call SpaceVim#api#import('vim#highlight').hide_in_normal('EndOfBuffer')
call s:apply_custom_space_keybindings()
call s:apply_custom_leader_keybindings()
if SpaceVim#layers#isLoaded('core#statusline')
set laststatus=2
call SpaceVim#layers#core#statusline#def_colors()

View File

@ -105,10 +105,23 @@ function! SpaceVim#custom#SPC(m, keys, cmd, desc, is_cmd) abort
endfunction
""
" Set the group name of custom key bindings.
" Set the group name of custom SPC key bindings.
function! SpaceVim#custom#SPCGroupName(keys, name) abort
call add(g:_spacevim_mappings_space_custom_group_name, [a:keys, a:name])
endfunction
""
" function for adding custom leader key bindings
function! SpaceVim#custom#leader(type, key, value, ...) abort
call add(g:_spacevim_mappings_leader_custom,
\ [a:type, a:key, a:value] + a:000)
endfunction
""
" Set the group name of custom Leader key bindings.
function! SpaceVim#custom#LeaderGroupName(keys, name) abort
call add(g:_spacevim_mappings_leader_custom_group_name, [a:keys, a:name])
endfunction
""
" This function offers user a way to add custom language specific key
@ -143,7 +156,7 @@ function! s:apply(config, type) abort
call SpaceVim#logger#warn('defx requires +python3!', 0)
continue
endif
" keep backward compatibility
" keep backward compatibility
elseif name ==# 'statusline_right_sections'
let name = 'statusline_right'
elseif name ==# 'statusline_right_sections'

View File

@ -1593,7 +1593,14 @@ SpaceVim#custom#SPC({m}, {keys}, {cmd}, {desc}, {is_cmd})
binding.
SpaceVim#custom#SPCGroupName({keys}, {name}) *SpaceVim#custom#SPCGroupName()*
Set the group name of custom key bindings.
Set the group name of custom SPC key bindings.
SpaceVim#custom#leader({type}, {key}, {value}) *SpaceVim#custom#leader()*
function for adding custom leader key bindings
SpaceVim#custom#LeaderGroupName({keys}, {name})
*SpaceVim#custom#LeaderGroupName()*
Set the group name of custom Leader key bindings.
SpaceVim#custom#LangSPC({ft}, {m}, {keys}, {cmd}, {desc}, {is_cmd})
*SpaceVim#custom#LangSPC()*