I am currently looking into different tricks for formatting text,
code, etc. in Vim.
I guess most users know the format-paragraph command gqq or the
reindent entire code 1G=G
But are there any other neat tricks - which ones are your favorites?
Well, though not exactly text/code reformatting, one of my
frequently used transformations comes when trying to batch rename
files.
dir /b *.rpt | vi -
or
ls *.rpt | vi -
and then make this cryptic change (which is the root of my answer
to your question for funky formatting tricks):
:g/^/s/.*/"&"/|t.|s/foo/bar/|-j
which makes the content the pair of quoted file-names, with my
desired change in the 2nd filename.
I can then just prefix each line with the appropriate OS command:
:%s/^/ren /
or
:%s/^/mv /
and then cram the whole result through my shell:
:%!cmd
or
:%!sh
any errors replace my original contents.
The result is a "rename" function with the smarts of regexp
search & replace.
Just one of those odd things I do... :)
-tim