2

I'm trying to deploy some static content upon writeing a buffer with an autocmd:

augroup dep
  autocmd!
  autocmd BufWritePost myProject/frontEnd/** :call s:deploy()
augroup END

The s:deploy function basically does the copy operation.

The frontEnd project has a bunch of directories with subdirectories for various JavaScript, CSS, and other files I want to be deployed.

I've found that my autocmd works great when saving files after starting Vim like this:

vim myProject/frontEnd/index.html

The autocmd also works when saving files after starting Vim like this:

vim myProject/frontEnd/js/file.js

But, when the autocmd does not execute when I start out at the above index.html and then use netrw to navigate to file.js. It's like the navigating kills the autocmd.

Any ideas on what is happening here?

EDIT for future Googlers:

The solution I was looking for (that @user21497's answer helped me realize) was to use a pre-pending wildcard in my autocmd:

autocmd BufWritePost */myProject/frontEnd/** :call s:deploy()
  • 3
    Your autocmd depends on vim being in the directory holding myProject; there are several options that could affect that. What does :echo g:netrw_keepdir show and what does :echo &acd show, for example. After navigating, what does :echo getcwd() show? – user21497 Feb 8 '16 at 21:44
  • 1
    @user21497 ah, thanks, your comment helped me realize the issue. I needed to use */myProject/frontEnd/** as my path. If you convert your comment to an answer I'll mark it as accepted. – Jonathan.Brink Feb 9 '16 at 0:13
3

Your autocmd depends on vim being in the directory holding myProject; there are several options that could affect that. What does :echo g:netrw_keepdir show and what does :echo &acd show, for example. After navigating, what does :echo getcwd() show?

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.