M
M
Maxim2015-10-31 11:35:25
linux
Maxim, 2015-10-31 11:35:25

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.
20151031bAFd7iwZfwdcHEZP_yziZu_large.png
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

2 answer(s)
A
Alexander Masterov, 2015-11-04
Antonikhin @STJ

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

Clear on hide:
augroup buffer-cleaner
  autocmd!
  autocmd BufHidden * CleanBuffers
augroup END

S
Shetani, 2015-10-31
@Shetani

Can delete unnecessary buffers? For example, as described here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question