From db66d23eb5582fba385be018aa4dcc83db39fa0c Mon Sep 17 00:00:00 2001 From: huzilin Date: Thu, 15 Oct 2020 20:32:17 +0800 Subject: [PATCH 1/4] allow buffer switch to last --- autoload/buffet.vim | 8 +++----- plugin/buffet.vim | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/autoload/buffet.vim b/autoload/buffet.vim index 7203b66..79c9fb1 100644 --- a/autoload/buffet.vim +++ b/autoload/buffet.vim @@ -353,12 +353,10 @@ endfunction function! buffet#bswitch(index) let i = str2nr(a:index) - 1 if i < 0 || i > len(s:buffer_ids) - 1 - echohl ErrorMsg - echom "Invalid buffer index" - echohl None - return + let buffer_id = s:buffer_ids[len(s:buffer_ids)-1] + else + let buffer_id = s:buffer_ids[i] endif - let buffer_id = s:buffer_ids[i] execute 'silent buffer ' . buffer_id endfunction diff --git a/plugin/buffet.vim b/plugin/buffet.vim index 60f89e7..f7e0b66 100644 --- a/plugin/buffet.vim +++ b/plugin/buffet.vim @@ -239,7 +239,7 @@ endfunction let g:buffet_bwipe_filters = ["buffet#bwipe_nerdtree_filter"] -for s:n in range(1, g:buffet_max_plug) +for s:n in range(0, g:buffet_max_plug) execute printf("noremap BuffetSwitch(%d) :call buffet#bswitch(%d)", s:n, s:n) endfor From 04d1abf40de03a92a7a45649b75d67f3baefe2f7 Mon Sep 17 00:00:00 2001 From: huzilin Date: Wed, 21 Oct 2020 11:12:21 +0800 Subject: [PATCH 2/4] Add switch to next buffer and prev buffer --- autoload/buffet.vim | 10 ++++++++++ plugin/buffet.vim | 3 +++ 2 files changed, 13 insertions(+) diff --git a/autoload/buffet.vim b/autoload/buffet.vim index 79c9fb1..386e048 100644 --- a/autoload/buffet.vim +++ b/autoload/buffet.vim @@ -360,6 +360,16 @@ function! buffet#bswitch(index) execute 'silent buffer ' . buffer_id endfunction +function! buffet#bnext() + let next_buffer_id = (s:last_current_buffer_id+1)%len(s:buffer_ids) + call buffet#bswitch(next_buffer_id) +endfunction + +function! buffet#bprev() + let next_buffer_id = (s:last_current_buffer_id-1) + call buffet#bswitch(next_buffer_id) +endfunction + " inspired and based on https://vim.fandom.com/wiki/Deleting_a_buffer_without_closing_the_window function! buffet#bwipe(bang, buffer) let btarget = s:GetBuffer(a:buffer) diff --git a/plugin/buffet.vim b/plugin/buffet.vim index f7e0b66..2f08b52 100644 --- a/plugin/buffet.vim +++ b/plugin/buffet.vim @@ -243,6 +243,9 @@ for s:n in range(0, g:buffet_max_plug) execute printf("noremap BuffetSwitch(%d) :call buffet#bswitch(%d)", s:n, s:n) endfor +noremap BuffetNext :call buffet#bnext() +noremap BuffetPrev :call buffet#bprev() + command! -bang -complete=buffer -nargs=? Bw call buffet#bwipe(, ) command! -bang -complete=buffer -nargs=? Bonly call buffet#bonly(, ) From be6e1ac2c5a469a14de139084c9bf60378e79468 Mon Sep 17 00:00:00 2001 From: huzilin Date: Wed, 21 Oct 2020 16:03:24 +0800 Subject: [PATCH 3/4] fix bugs --- autoload/buffet.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/autoload/buffet.vim b/autoload/buffet.vim index 386e048..7f9d08c 100644 --- a/autoload/buffet.vim +++ b/autoload/buffet.vim @@ -361,13 +361,14 @@ function! buffet#bswitch(index) endfunction function! buffet#bnext() - let next_buffer_id = (s:last_current_buffer_id+1)%len(s:buffer_ids) - call buffet#bswitch(next_buffer_id) + let current_buffer_id_i = index(s:buffer_ids, s:last_current_buffer_id) + let next_buffer_id_i = (current_buffer_id_i+2)%len(s:buffer_ids) + call buffet#bswitch(next_buffer_id_i) endfunction function! buffet#bprev() - let next_buffer_id = (s:last_current_buffer_id-1) - call buffet#bswitch(next_buffer_id) + let current_buffer_id_i = index(s:buffer_ids, s:last_current_buffer_id) + call buffet#bswitch(current_buffer_id_i) endfunction " inspired and based on https://vim.fandom.com/wiki/Deleting_a_buffer_without_closing_the_window From 875fdaec25ed4f3c164aac956aa7ee8a018a59b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=AD=90=E9=BA=9F?= Date: Thu, 25 Nov 2021 14:26:54 +0800 Subject: [PATCH 4/4] support switch buffer --- README.md | 6 +++++- autoload/buffet.vim | 23 +++++++++++++++++++++++ plugin/buffet.vim | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1ea3b0..fee542f 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,11 @@ nmap 6 BuffetSwitch(6) nmap 7 BuffetSwitch(7) nmap 8 BuffetSwitch(8) nmap 9 BuffetSwitch(9) -nmap 0 BuffetSwitch(10) +nmap 0 BuffetSwitch(0) " to the last one +nmap ] BuffetNext +nmap [ BuffetPrev +nmap BuffetMoveLeft +nmap BuffetMoveRight ``` This will allow you to switch between buffers 1 - 10. You can get more `` diff --git a/autoload/buffet.vim b/autoload/buffet.vim index 7f9d08c..81edeed 100644 --- a/autoload/buffet.vim +++ b/autoload/buffet.vim @@ -360,6 +360,29 @@ function! buffet#bswitch(index) execute 'silent buffer ' . buffer_id endfunction +function! buffet#moveLeft() + let cIdx = index(s:buffer_ids, s:last_current_buffer_id) + let idx = str2nr(cIdx) + if idx <= 0 + return + endif + let tmp = s:buffer_ids[idx] + let s:buffer_ids[idx] = s:buffer_ids[idx-1] + let s:buffer_ids[idx-1] = tmp + return s:Render() +endfunction + +function! buffet#moveRight() + let cIdx = index(s:buffer_ids, s:last_current_buffer_id) + if cIdx > len(s:buffer_ids)-2 + return + endif + let tmp = s:buffer_ids[cIdx] + let s:buffer_ids[cIdx] = s:buffer_ids[cIdx+1] + let s:buffer_ids[cIdx+1] = tmp + return s:Render() +endfunction + function! buffet#bnext() let current_buffer_id_i = index(s:buffer_ids, s:last_current_buffer_id) let next_buffer_id_i = (current_buffer_id_i+2)%len(s:buffer_ids) diff --git a/plugin/buffet.vim b/plugin/buffet.vim index 2f08b52..bb748b5 100644 --- a/plugin/buffet.vim +++ b/plugin/buffet.vim @@ -245,6 +245,8 @@ endfor noremap BuffetNext :call buffet#bnext() noremap BuffetPrev :call buffet#bprev() +noremap BuffetMoveLeft :call buffet#moveLeft() +noremap BuffetMoveRight :call buffet#moveRight() command! -bang -complete=buffer -nargs=? Bw call buffet#bwipe(, ) command! -bang -complete=buffer -nargs=? Bonly call buffet#bonly(, )