1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-13 02:05:40 +08:00

Fix key binding g r (#3728)

This commit is contained in:
Wang Shidong 2020-08-25 23:15:37 +08:00 committed by GitHub
parent b05721a335
commit 5665e23236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 36 deletions

View File

@ -34,16 +34,21 @@ function! s:self.realTabBuffers(id) abort
return filter(copy(tabpagebuflist(a:id)), 'buflisted(v:val) && getbufvar(v:val, "&buftype") ==# ""')
endfunction
function! s:tab_closed_handle() abort
if expand('<afile>') <= get(s:, 'previous_tabpagenr', 0)
let s:previous_tabpagenr -= 1
endif
endfunction
" as vim do not support tabpagenr('#')
augroup spacevim_api_vim_tab
autocmd!
autocmd TabLeave * let s:previous_tabpagenr = tabpagenr()
autocmd TabClosed * call <SID>tab_closed_handle()
augroup END
function! s:self.previous_tabpagenr() abort
let tabsinfo = self.__cmp.execute('tabs')
let number = 0
for line in split(tabsinfo, "\n")
if line =~# '^Tab page \d'
let number = str2nr(matchstr(line, '\d\+'))
elseif line =~# '^#'
return number
endif
endfor
return get(s:, 'previous_tabpagenr', 0)
endfunction
function! SpaceVim#api#vim#tab#get() abort

View File

@ -9,6 +9,7 @@
scriptencoding utf-8
let s:SYSTEM = SpaceVim#api#import('system')
let s:TAB = SpaceVim#api#import('vim#tab')
" Default options {{{
function! SpaceVim#default#options() abort
@ -262,9 +263,9 @@ function! SpaceVim#default#keyBindings() abort
cnoremap <C-s> <C-u>w<CR>
" Tabs
nnoremap <silent>g0 :<C-u>tabfirst<CR>
nnoremap <silent>g$ :<C-u>tablast<CR>
nnoremap <silent><expr> gr tabpagenr('#') > 0 ? ':exe "tabnext " . tabpagenr("#")<cr>' : ''
nnoremap <silent> g0 :<C-u>tabfirst<CR>
nnoremap <silent> g$ :<C-u>tablast<CR>
nnoremap <silent> gr :<C-u>call <SID>switch_tabs()<CR>
" Remove spaces at the end of lines
nnoremap <silent> ,<Space> :<C-u>silent! keeppatterns %substitute/\s\+$//e<CR>
@ -351,4 +352,11 @@ function! SpaceVim#default#Customfoldtext() abort
return prefix . line . expansionString . foldSizeStr . foldPercentage . foldLevelStr
endfunction
function! s:switch_tabs() abort
let previous_tab = s:TAB.previous_tabpagenr()
if previous_tab > 0
exe "tabnext " . previous_tab
endif
endfunction
" vim:set et sw=2:

View File

@ -629,21 +629,26 @@ endfunction
如果只有一个 Tab, Buffers 将被罗列在标签栏上,每一个包含:序号、文件类型图标、文件名。如果有不止一个 Tab, 那么所有 Tab 将被罗列在标签栏上。标签栏上每一个 Tab 或者 Buffer 可通过快捷键 `<Leader> number` 进行快速访问,默认的 `<Leader>``\`
| 快捷键 | 功能描述 |
| ------------ | ------------------ |
| `<Leader> 1` | 跳至标签栏序号 1 |
| `<Leader> 2` | 跳至标签栏序号 2 |
| `<Leader> 3` | 跳至标签栏序号 3 |
| `<Leader> 4` | 跳至标签栏序号 4 |
| `<Leader> 5` | 跳至标签栏序号 5 |
| `<Leader> 6` | 跳至标签栏序号 6 |
| `<Leader> 7` | 跳至标签栏序号 7 |
| `<Leader> 8` | 跳至标签栏序号 8 |
| `<Leader> 9` | 跳至标签栏序号 9 |
| `g r` | 跳至前一个标签序号 |
| 快捷键 | 功能描述 |
| ------------ | --------------------------------------- |
| `<Leader> 1` | 跳至标签栏序号 1 |
| `<Leader> 2` | 跳至标签栏序号 2 |
| `<Leader> 3` | 跳至标签栏序号 3 |
| `<Leader> 4` | 跳至标签栏序号 4 |
| `<Leader> 5` | 跳至标签栏序号 5 |
| `<Leader> 6` | 跳至标签栏序号 6 |
| `<Leader> 7` | 跳至标签栏序号 7 |
| `<Leader> 8` | 跳至标签栏序号 8 |
| `<Leader> 9` | 跳至标签栏序号 9 |
| `g r` | 跳至前一个 Tab常用于两个 Tab 来回切换 |
**注意:** 两个缓冲区来回切换的快捷键是 `SPC Tab`
可阅读[缓冲区管理](#缓冲区管理)部分内容,了解更多缓冲区相关的快捷键。
标签栏上也支持鼠标操作,左键可以快速切换至该标签,中键删除该标签。该特性只支持 Neovim并且需要 `has('tablineat')` 特性。
**注意:** 这一特性仅限于Neovim并且 `has('tablineat')` 返回 `true`
| 快捷键 | 功能描述 |
| ---------------- | ------------ |
| `<Mouse-left>` | 切换至该标签 |

View File

@ -652,18 +652,21 @@ the index, bufname and the filetype icon. If there are more than one tab, all
tabs will be listed on the tabline. Each item can be quickly accessed by using
`<Leader> number`. Default `<Leader>` is `\`.
| Key Bindings | Descriptions |
| ------------ | -------------------------- |
| `<Leader> 1` | Jump to index 1 on tabline |
| `<Leader> 2` | Jump to index 2 on tabline |
| `<Leader> 3` | Jump to index 3 on tabline |
| `<Leader> 4` | Jump to index 4 on tabline |
| `<Leader> 5` | Jump to index 5 on tabline |
| `<Leader> 6` | Jump to index 6 on tabline |
| `<Leader> 7` | Jump to index 7 on tabline |
| `<Leader> 8` | Jump to index 8 on tabline |
| `<Leader> 9` | Jump to index 9 on tabline |
| `g r` | Go to previous tab |
| Key Bindings | Descriptions |
| ------------ | ----------------------------------------------- |
| `<Leader> 1` | Jump to index 1 on tabline |
| `<Leader> 2` | Jump to index 2 on tabline |
| `<Leader> 3` | Jump to index 3 on tabline |
| `<Leader> 4` | Jump to index 4 on tabline |
| `<Leader> 5` | Jump to index 5 on tabline |
| `<Leader> 6` | Jump to index 6 on tabline |
| `<Leader> 7` | Jump to index 7 on tabline |
| `<Leader> 8` | Jump to index 8 on tabline |
| `<Leader> 9` | Jump to index 9 on tabline |
| `g r` | Switch to alternate tab (switch back and forth) |
**Note:** `SPC Tab` is the key binding for switching to alternate buffer.
Read [Buffers and Files](#buffers-and-files) section for more info.
SpaceVim tabline also supports mouse click, left mouse button will switch to buffer,
while middle button will delete the buffer.