1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-04-14 15:19:12 +08:00

feat(tabline): add ctrl-shift-left/right key binding

ref: https://github.com/SpaceVim/SpaceVim/issues/1917
This commit is contained in:
wsdjeg 2022-04-07 13:17:22 +08:00
parent ca58d3111b
commit ab64e20617
2 changed files with 70 additions and 0 deletions

View File

@ -16,6 +16,17 @@
" name = "core#tabline"
" enable = false
" <
" @subsection Layer options
"
" 1. `enable_default_mappings`: Enable/disable default key bindings. This is
" enabled by default.
"
" @subsection Key bindings
" >
" Key binding Description
" Ctrl-Shift-Right Move current tabpage to the right
" Ctrl-Shift-Left Move current tabpage to the left
" <
scriptencoding utf-8
@ -54,6 +65,7 @@ let s:i_separators = {
\ 'nil' : ['', ''],
\ }
let s:enable_default_mappings = 1
function! s:get_no_empty(a, b) abort
if empty(a:a)
@ -63,6 +75,38 @@ function! s:get_no_empty(a, b) abort
endif
endfunction
function! s:move_tabpage(direction)
" get number of tab pages.
let ntp = tabpagenr("$")
if ntp > 1
" get number of current tab page.
let ctpn = tabpagenr()
if a:direction > 0
let index = (ctpn + a:direction) % ntp
if index == 0
let index = ntp
elseif index == 1
let index = 0
endif
else
let index = (ctpn + a:direction) % ntp
if index < 0
let index = ntp + index
endif
if index == 0
let index = ntp
elseif index == 1
let index = 0
else
let index -= 1
endif
endif
" move tab page.
execute "tabmove ".index
endif
endfunction
function! s:tabname(bufnr) abort
let name = bufname(a:bufnr)
if name ==# '\[Vader\]'
@ -471,6 +515,10 @@ function! SpaceVim#layers#core#tabline#config() abort
autocmd ColorScheme * call SpaceVim#layers#core#tabline#def_colors()
augroup END
if s:enable_default_mappings
nnoremap <silent> <C-S-Left> :call <SID>move_tabpage(-1)<CR>
nnoremap <silent> <C-S-Right> :call <SID>move_tabpage(1)<CR>
endif
let shift_keys = {
\ '1': '!',
@ -556,3 +604,13 @@ function! SpaceVim#layers#core#tabline#health() abort
call SpaceVim#layers#core#tabline#config()
return 1
endfunction
function! SpaceVim#layers#core#tabline#set_variable(var) abort
let s:enable_default_mappings = get(a:var, 'enable_default_mappings', s:enable_default_mappings)
endfunction
function! SpaceVim#layers#core#tabline#get_options() abort
return ['enable_default_mappings']
endfunction

View File

@ -1773,6 +1773,18 @@ tabline, just disable this layer
name = "core#tabline"
enable = false
<
LAYER OPTIONS
1. `enable_default_mappings`: Enable/disable default key bindings. This is
enabled by default.
KEY BINDINGS
>
Key binding Description
Ctrl-Shift-Right Move current tabpage to the right
Ctrl-Shift-Left Move current tabpage to the left
<
==============================================================================
CSCOPE *SpaceVim-layers-cscope*