How to automatically execute a shell command after saving a file in Vim?

VimAutocmd

Vim Problem Overview


This is because I'd like to automatically run tests after each file save.

I have looked at autocmd and BufWritePost but cannot make it work.

Vim Solutions


Solution 1 - Vim

This runs run_tests.sh after any file is saved, with the current filename as the only parameter:

:autocmd BufWritePost * !run_tests.sh <afile>

View the auto-command with:

:autocmd BufWritePost *

And remove all auto-commands from the previous with:

:autocmd! BufWritePost *

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRunning TurtleView Question on Stackoverflow
Solution 1 - VimAlex HowellView Answer on Stackoverflow