1

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

1
  • 1
    Yes. Start by reading :help autocmd and :help BufWrite. – romainl May 17 '16 at 20:12
3

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
    endif
    let c += 1
  endwhile

  return 0
endfunction

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

autocmd BufWrite * :call DoOnlyWithArg()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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