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.
Comments in languages such as BASH
Tables, which could be processed by
- The 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.h"
and 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 syntax
EDIT: Here is another concrete example
# To sort: +2,/)/-1!column -t | sort JUNKFILES = $(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 \ )