1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-14 02:35:41 +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") ==# ""') return filter(copy(tabpagebuflist(a:id)), 'buflisted(v:val) && getbufvar(v:val, "&buftype") ==# ""')
endfunction endfunction
function! s:self.previous_tabpagenr() abort function! s:tab_closed_handle() abort
let tabsinfo = self.__cmp.execute('tabs') if expand('<afile>') <= get(s:, 'previous_tabpagenr', 0)
let number = 0 let s:previous_tabpagenr -= 1
for line in split(tabsinfo, "\n")
if line =~# '^Tab page \d'
let number = str2nr(matchstr(line, '\d\+'))
elseif line =~# '^#'
return number
endif endif
endfor 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
return get(s:, 'previous_tabpagenr', 0)
endfunction endfunction
function! SpaceVim#api#vim#tab#get() abort function! SpaceVim#api#vim#tab#get() abort

View File

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

View File

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

View File

@ -653,7 +653,7 @@ tabs will be listed on the tabline. Each item can be quickly accessed by using
`<Leader> number`. Default `<Leader>` is `\`. `<Leader> number`. Default `<Leader>` is `\`.
| Key Bindings | Descriptions | | Key Bindings | Descriptions |
| ------------ | -------------------------- | | ------------ | ----------------------------------------------- |
| `<Leader> 1` | Jump to index 1 on tabline | | `<Leader> 1` | Jump to index 1 on tabline |
| `<Leader> 2` | Jump to index 2 on tabline | | `<Leader> 2` | Jump to index 2 on tabline |
| `<Leader> 3` | Jump to index 3 on tabline | | `<Leader> 3` | Jump to index 3 on tabline |
@ -663,7 +663,10 @@ tabs will be listed on the tabline. Each item can be quickly accessed by using
| `<Leader> 7` | Jump to index 7 on tabline | | `<Leader> 7` | Jump to index 7 on tabline |
| `<Leader> 8` | Jump to index 8 on tabline | | `<Leader> 8` | Jump to index 8 on tabline |
| `<Leader> 9` | Jump to index 9 on tabline | | `<Leader> 9` | Jump to index 9 on tabline |
| `g r` | Go to previous tab | | `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, SpaceVim tabline also supports mouse click, left mouse button will switch to buffer,
while middle button will delete the buffer. while middle button will delete the buffer.