Many sections of stuff we right is such that it could be automatically formatted by user defined rules. Here are a couple of examples:List of include files in languages such as C. It is customary to sort these alphabetically, and this sorting is also part of style guides such as those of Google.Ditto for usepackage in LaTeXComments in languages such as BASHTables, which could be processed by column -tThe entire file, from which I would like to automatically remove spaces at eoln, and repeated empty lines.Doing these in vi is not tough. Just do something like !}sort -u. What's annoying is the need to do this repeatedly. Ideally, I would write:// AUTO: `!}sort -u | column -t`#include z.h#include a.h#include b.hand each time I save my file, these specially marked commands will execute.  Is this possible to do? Are there any plugins that do something similar?Inspiration may be drawn from this question: Apply formating with a script, or have ftplugin format particular text based on syntaxEDIT: Here is another concrete example# To sort: +2,/)/-1!column -t | sortJUNKFILES = $(wildcard \*~             \*.aux          \*.out          \*.bbl          \*.bcf          \*.blg          \*blx.bib       \[dD]elme*      \DELME*         \*.dvi          \*.fdb_latexmk  \*.fls          \*.listing      \*.log          \$(MAIN).pdf    \*.o            \*.out          \*.run.xml      \*.synctex.gz   \)
Auto sorting of lists of include files
vimscript
You want to automatically run a command when you write your buffer, and the n save your buffer after the command.. This means you're looking for an autocmd that runs during a BufWrite.Place something like this into your .vimrc:autocmd BufWrite *.c call Libsort()function Libsort()    normal mfgg}    let lineNumber = line('.') - 1    execute '1,' . lineNumber . '!sort -u'    normal 'fendfunctionThat should do something similar to what you want. When you write your current buffer, if it is a .c file, it marks your current position, goes to the start of the document and sorts the first paragraph, and then returns to the mark. I wrote that function quite quickly, so it's not error checked or anything but should give you an idea for a starting point.