aboutsummaryrefslogtreecommitdiff
path: root/autoload/buf_utils.vim
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2020-11-14 14:29:37 +0800
committerjdhao <jdhao@hotmail.com>2020-11-14 14:29:37 +0800
commit2ad432088fa3228319e85564f0735e33ea3b6e2f (patch)
treeceea0c70452b6ff9d66b178269ff11ed1218a9b7 /autoload/buf_utils.vim
parentb5087e3665fffb1caee95b3ff78130fadd613f39 (diff)
move function to autoload dir
Diffstat (limited to 'autoload/buf_utils.vim')
-rw-r--r--autoload/buf_utils.vim26
1 files changed, 26 insertions, 0 deletions
diff --git a/autoload/buf_utils.vim b/autoload/buf_utils.vim
new file mode 100644
index 0000000..db34ae0
--- /dev/null
+++ b/autoload/buf_utils.vim
@@ -0,0 +1,26 @@
+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
+ echohl WarningMsg | echomsg 'Invalid bufnr: ' a:count | echohl None
+ 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