I recently start using vim for writing tex files. I found that an
extra space is always added between lines after reformatting (e.g.,
"gq}").
For example:
Original text:
a...b
c...d
d...e
Reformatted text:
a...b c...d d...e
Is there an option that I can override this behavior?
The short answer is "no, there is no such option". A space is
semantically a place that can be squished or broken when
reformatting. It sounds like you want a non-breaking-space for
some reason. As this is tex code, according to a quick google on
the matter, it looks like tex uses a tilde ("~") as its
non-breaking space character. If the spaces are significant, you
may want to change them to
a~~~b
c~~~d
d~~~e
(This is a shot-from-the-hip, as I know nothing about tex other
than what I saw in the google results)
Alternatively, you can use some character that you're not
otherwise using and do a "decorate/operate/undecorate" sequence,
such as
:'<,'>s/ /_/g
then do your reformatting:
gq}
then reselect the text and remove those changes:
:'<,'>s/_/ /g
You would have to choose some character that wasn't already in
use within that range...and perhaps might need to add that
character to the 'iskeyword' collection so that it doesn't get
treated as a breakable character.
If you're just joining the lines, rather than reflowing the
lines, you can highlight the range and use "J" to join them, or
you can (if you've previously selected the lines in question) use
:'<,'>j
Just a few ideas to try and help you along...
-tim