Answer the question
In order to leave comments, you need to log in
Why does VIM slow down after a few hours of work?
After a couple of hours of work in one project, vim starts to slow down.
Down in the airline, where the buffers are, the buffer number increases to 500+ and the brakes begin.
Tell me, please, what could be the problem or how can I clear the buffers?
Answer the question
In order to leave comments, you need to log in
Close buffers with bwipeout to free up memory , or bunload if you want to leave the buffer name in the list. Hidden buffers can be mass-cleaned with a self-written command:
UPD: It turned out that for some plugins to work correctly, you need to leave at least one last hidden buffer, so I slightly updated the code, adding the ability to adjust their number, as well as an explicit force (!) mode for the command. Perhaps it is already worth putting all this into a plugin, where it will be possible to rewrite the code normally and optimally separate the functionality, for example, add caching and the ability to save buffers.
let g:bufcleaner_max_save = 2
command! -bar -bang -nargs=? CleanBuffers call s:cleanBuffers("<bang>")
function! s:cleanBuffers(...) abort
let force = a:0 >= 1 && a:1 ==# '!'
redir => bufs
silent! buffers
redir END
let hidden = []
for buf in map(split(bufs, '\n'), 'split(v:val)')
let bufnr = buf[0] + 0
let flags = matchstr(join(buf[1:]), '^.*\ze\s\+"')
let mod = substitute(flags, '\s*', '', 'g')
let hide = mod ==# 'h' || mod ==# 'h+'
\ && (force || input(printf("\n%s not saved.\nDelete anyway? [Y]es, (N)o: ",
\ bufname(bufnr))) =~? '^y\%[es]$')
if hide
call add(hidden, bufnr)
endif
endfor
let saved = get(g:, 'bufcleaner_max_save', 3)
let target = len(hidden) > saved ? join(hidden[0:-saved-1], ' ') : ''
if !empty(target)
silent! execute 'bwipeout!' target
endif
endfunction
augroup buffer-cleaner
autocmd!
autocmd BufHidden * CleanBuffers
augroup END
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question