5

Question

Working with text and various markup languages in Vim I have recently experimented with the conceal feature to hide some of the more verbose markup. I switch conceal off when writing and editing and switch it on when searching and reading. Conceal increases readability, but it ruins paragraph formatting, which decreases readability. To benefit from conceal without losing formatting I would like to be able to format a paragraph as if the concealed markup was not there. How can I achieve this?

Context

I normally use MacVim with Vim 7.4.258.

I use par to format my text. My 'formatprg' is set to par -qw79 and I use gqip and friends to apply formatting.

I have read the help topic on formatexpr and it gave me the idea to write something in VimL that removes the concealed markup before filtering the text through formatprg, then reapplies it to the formatted paragraph. Is this a reasonable approach? It strikes me as possible but difficult and I am hoping there is a simpler way.

Example

Here is a current example using vim-latex-1.8.23 (latex suite) and its default concealment. There are worse cases but this will illustrate my problem. Compare the following paragraph with minor LaTeX markup as it is appears in a buffer with conceallevel=0

Let me begin with the former idea, the modal orientation. The traditional
question that I mentioned above, i.e., Are there genuine naming devices? is
a \textit{semantical} question. Kripke's distinctive strategy is to tackle it
by attending first to a \textit{metaphysical} question. We focus on objects,
the design\textit{ata}, and their modal properties. We do not begin our
semantical investigation by looking at the design\textit{ators} and their
purely linguistic features. Not at all. The intuitive test for rigidity that
Kripke devises (N&N, 48/9) reflects this point. We start with an individual
(Nixon), and we observe that \textit{that} individual couldn't have failed to
be Nixon. Thus, the property \textit{being Nixon} applies to him necessarily
(or at least essentially, a distinction to which we shall return below).

with the same paragraph when the markup is concealed

Let me begin with the former idea, the modal orientation. The traditional
question that I mentioned above, i.e., Are there genuine naming devices? is
a semantical question. Kripke's distinctive strategy is to tackle it
by attending first to a metaphysical question. We focus on objects,
the designata, and their modal properties. We do not begin our
semantical investigation by looking at the designators and their
purely linguistic features. Not at all. The intuitive test for rigidity that
Kripke devises (N&N, 48/9) reflects this point. We start with an individual
(Nixon), and we observe that that individual couldn't have failed to
be Nixon. Thus, the property being Nixon applies to him necessarily
(or at least essentially, a distinction to which we shall return below).
3
  • 1
    I wanted to tag this question [formatting] and [conceal], but I was not allowed to create new tags. Perhaps someone else could do that?
    – jjaderberg
    Commented Mar 11, 2015 at 9:41
  • I thought that was what I did ask. Does it seem like I am asking about par? I mention it by way of context–it is how I currently format text. I am asking for alternatives to my current method that accommodate the discrepancy between displayed and actual line length introduced by concealing, I am not invested in any particular formatting method. Thanks for retagging (though I did not intend this question to be about syntax highlighting or external commands).
    – jjaderberg
    Commented Mar 11, 2015 at 10:14
  • So you do ... I blame mornings without any coffee yet :-/ ... conceal seems to be a feature of Vim's syntax highlighting, which is why I tagged it as such :-) Commented Mar 11, 2015 at 10:28

1 Answer 1

5

The conceal feature is entirely visual; i.e. it only affects what is displayed in Vim (to make it easier on the eye). As such, there is no interaction with Vim commands that change the actual text in the buffer (such as :substitute or reformatting); movement commands will just jump over the concealed characters.

With that, it is indeed difficult to implement a 'formatexpr' that breaks the text as it appears with conceal turned on. As conceal is implemented by syntax highlighting, you'd either have to interact with the buffer text and query for the syntax attributes (via synID() and synconcealed()), which is cumbersome and likely slow, or you'd have to duplicate the conceal definitions and provide those to your custom format expression, effectively reimplementing conceal there.


I can see your motivation, but given the described difficulties (and that it forces Vim into the direction of WYSIWYG, for which it expressly isn't designed), I would advise to live with the discrepancies. For Latex in particular, there are several "real" WYSIWYG editors you could alternatively use.

1
  • 1
    Thanks for confirming and indicating a possible (implausible) route. I don't see what this has to do with WYSIWYG, which ought to show something like \marginpar{text} in a margin rather than just conceal the command. Concealing is a Vim feature and tweaking how it interacts with other features doesn't amount to looking for a different editor, surely. But I understand that what I'm asking for is nontrivial and unless someone offers more detailed suggestions I'll accept your answer. Despite your WYSIWYG curse ;-)
    – jjaderberg
    Commented Mar 20, 2015 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.