0

My buffer is able to reload every time I pull changes from the remote, with:

autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif
autocmd FileChangedShellPost *
      \ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None

I recently added auto-formatting for Bazel BUILD files, by adding this to my init.vim:

autocmd BufWritePost BUILD !buildifier <afile>

It works in that the file is formatted by buildifier, but my buffer is not automatically reloaded to reflect the changes.

Typing :e does refresh the buffer, but I can't seem to concatenate this :e to !buildifier <afile>. I tried:

autocmd BufWritePost BUILD !buildifier <afile> | :e

and

autocmd BufWritePost BUILD !buildifier <afile> | e

but both cases had :e or e recognized as an external command.

What's lacking here to make my buffer auto-reload?

1 Answers1

1

What is happening is that vim is running all of "buildifier <afile> | e" as one shell command, which means the shell is being told to pipe the output of "buildifier" to the "e" shell command (which doesn't even exist for me so I get an error from the shell). You need to prevent that by explicitly telling Vim the "boundary" of the shell command:

autocmd BufWritePost BUILD execute "!buildifier <afile>" | e
Heptite
  • 1,046
  • 6
  • 14