Is it possible to create an autocommand that executes whenever one of the files in the arglist is written to?

  • 1
    Yes. Start by reading :help autocmd and :help BufWrite.
    – romainl
    May 17, 2016 at 20:12

1 Answer 1


There is not a specific Autocommand event for writes to the arglist files. What you can do is create a function that checks if the file is in the arglist and then set that to the BufWrite event. So all buffer writes would trigger this function, but only arglist'd files would actually do anything.

You can use bufname("%") to find the current buffer's name, and then use argv() and argc() to find the arglist entries.

function! IsBufInArgs()
  let c = 0
  while c <= argc()
    if argv(c) == bufname("%")
      return 1
    let c += 1

  return 0

function! DoOnlyWithArg()
  if IsBufInArgs() == 1
    echo "Do something here"

autocmd BufWrite * :call DoOnlyWithArg()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.