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 7203b66..81edeed 100644 --- a/autoload/buffet.vim +++ b/autoload/buffet.vim @@ -353,15 +353,47 @@ 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 +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) + call buffet#bswitch(next_buffer_id_i) +endfunction + +function! buffet#bprev() + 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 function! buffet#bwipe(bang, buffer) let btarget = s:GetBuffer(a:buffer) diff --git a/plugin/buffet.vim b/plugin/buffet.vim index 60f89e7..bb748b5 100644 --- a/plugin/buffet.vim +++ b/plugin/buffet.vim @@ -239,10 +239,15 @@ 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 +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(, )