Skip to content

Instantly share code, notes, and snippets.

@kkoomen
Last active August 24, 2025 08:01
Show Gist options
  • Save kkoomen/68319b08ab843ce67cf7b282b0b2fd24 to your computer and use it in GitHub Desktop.
Save kkoomen/68319b08ab843ce67cf7b282b0b2fd24 to your computer and use it in GitHub Desktop.
Vim-Plug: Run PlugUpdate every week automatically

This snippet will check every time you run Vim whether it updated all your Plug packages for you. It will do this once a week automatically for you.

Add the following to your .vimrc:

function! OnVimEnter() abort
  " Run PlugUpdate every week automatically when entering Vim.
  if exists('g:plug_home')
    let l:filename = printf('%s/.vim_plug_update', g:plug_home)
    if !filereadable(l:filename)
      call writefile([], l:filename)
    endif

    let l:this_week = strftime('%Y_%V')
    let l:contents = readfile(l:filename)
    if index(l:contents, l:this_week) < 0
      call execute('PlugUpdate')
      call writefile([l:this_week], l:filename, 'a')
    endif
  endif
endfunction

autocmd VimEnter * call OnVimEnter()
@acejacek
Copy link

@orrpeles You can run the snippet in a headless way by running vim +PlugUpdate +qa > /dev/null 2&>1. This won't show vim but will run vim with the given commands.

This is great idea. I added this snippet to my Ansible playbook, so now also all my Vim Plugins on all machines are updated periodically:

- name: VimPlugin
      ansible.builtin.shell:
        cmd: vim +plugUpdate +qa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment