1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00
jdhao-nvim-config/autoload/buf_utils.vim
2021-07-24 14:53:48 +08:00

27 lines
659 B
VimL

function! buf_utils#GoToBuffer(count, direction) abort
if a:count == 0
if a:direction ==# 'forward'
bnext
elseif a:direction ==# 'backward'
bprevious
else
echoerr 'Bad argument ' a:direction
endif
return
endif
" Check the validity of buffer number.
if index(s:GetBufNums(), a:count) == -1
call utils#Log('Invalid bufnr: ' . a:count, 'error')
return
endif
" Do not use {count} for gB (it is less useful)
if a:direction ==# 'forward'
silent execute('buffer' . a:count)
endif
endfunction
function! s:GetBufNums() abort
return map(copy(getbufinfo({'buflisted':1})), 'v:val.bufnr')
endfunction