As I am working on a project I like to keep a plain text log file of my progress using MacVim. I use Typinator to produce a timecode (but how the timecode is generated is irrelevant to the problem).
Instead of this:
07:11 The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog.
I would like this:
07:11 The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog.
Is there a fairly simple means for achieving this behavior? Can vim be made to trigger hanging indent when it sees a match for a target regular expression? To be painfully precise, I always precede the timecode with 1 space and follow it with 2 spaces before typing the entry.
The key here is come up with a formatlistpat
(format list pattern) specification that will do what you want, and set the necessary flags to enable it to be implemented.
This does the trick:
:set formatlistpat=^\\s\\d\\d[:]\\d\\d\\s\\s
:set breakindent
:set formatoptions=tcqn
In the remainder of this post I will provide some information that might be helpful to others attempting similar things.
The default value of formatlistpat
, which can be found with :set formatlistpat?
is designed as follows:
The default recognizes a number, followed by an optional punctuation character and white space.
which translates to
^\s*\d+[\]:.)}\t ]\s* where ^ = start of line \s* = one or more spaces \d+ = one or more digits (why not \d*?) [ = start a character class \] = character ] : = character : . = character . ) = character ) } = character } \t = tab " " = space ] = end a character class
Once you have done a :set formatlistpat
command, it replaces whatever pattern you had before. You must also :set breakindent
and add the n
option to formatoptions
(as I show above).