diff options
author | Teddy Wing | 2020-10-21 19:38:21 +0200 |
---|---|---|
committer | Teddy Wing | 2020-10-21 19:53:43 +0200 |
commit | 652e068e951464c1b37535a8fe34a448b6bf5742 (patch) | |
tree | 69a1f1413d084c0f2c4d857c08a2f891a6e741b5 /bundle/buffer-delete/autoload/buffer_delete.vim | |
parent | 9e00408c99b61561af6ead483626a614a8b54b05 (diff) | |
download | dotvim-652e068e951464c1b37535a8fe34a448b6bf5742.tar.bz2 |
Add 'buffer-delete' plugin
I was having trouble with slow `<C-p>` completion, and figured out it
was due to the fact that I had about 300 buffers open.
Many of these buffers weren't being actively used, and were just loaded
in from Vim sessions past. When I removed the unloaded buffers,
completion sped up like a whistle.
Thanks to 'sidyll' (https://stackoverflow.com/users/557306/sidyll) on
Stack Overflow for explaining how to get "all" buffer numbers (or at
least all possible buffer numbers up to the highest one open), as well
as the filtering logic:
https://stackoverflow.com/questions/17931507/vimscript-number-of-listed-buffers/17933352#17933352
I leveraged the above to get the buffer numbers of all unloaded buffers,
then delete the buffers by number.
It was originally a temporary command-mode line, but I decided it could
be beneficial to save the code just in case I need it again.
Diffstat (limited to 'bundle/buffer-delete/autoload/buffer_delete.vim')
-rw-r--r-- | bundle/buffer-delete/autoload/buffer_delete.vim | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/bundle/buffer-delete/autoload/buffer_delete.vim b/bundle/buffer-delete/autoload/buffer_delete.vim new file mode 100644 index 0000000..316cfe8 --- /dev/null +++ b/bundle/buffer-delete/autoload/buffer_delete.vim @@ -0,0 +1,11 @@ +" Delete all unloaded buffers. These are buffers that aren't active or hidden. +" Usually they come from a reinitialised session. +function! buffer_delete#Unloaded() + let all = range(1, bufnr('$')) + let unloaded = filter(all, {_i, v -> !bufloaded(v)}) + + for i in unloaded + " Use silent because some buffer numbers may not exist. + silent! execute 'bdelete ' . i + endfor +endfunction |