Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

History ignores in VIM

Tags:

vim

Is there an option similar to Bash's HISTIGNORE to dump some useless lines from the command history (let's say :wq or :help.*)?

If not, I reckon a simple DIY way would be to parse manually the .viminfo file with a regex predicate. Is there a specific VIM linking that could sync the parsing with a change in the .viminfo file ?

like image 843
Bertrand Caron Avatar asked Jun 26 '13 02:06

Bertrand Caron


1 Answers

Unfortunately, answer is No. But if you allow put H into your typing commands, it maybe possible. How about this?

https://gist.github.com/5864587

let g:histignore = '^buf:^history'
function! s:h(commandline)
  call histdel(':', '^H\s')
  let oldhist=&history
  try
    if len(filter(split(g:histignore, ':'), 'a:commandline =~ v:val')) == 0
      call histadd(':', a:commandline)
    endif
    set history=0
    exe a:commandline
  catch
    echohl ErrorMsg | echomsg v:exception | echohl None
  finally
    let &history=oldhist
    unlet oldhist
  endtry
endfunction
command! -nargs=+ H call s:h(<q-args>)

Put into this file as your ~/.vim/plugin/h.vim

:H buffers

This is not stored in :history, But

:H ls

This will be stored.

like image 129
mattn Avatar answered Sep 20 '22 04:09

mattn