Friday, February 7, 2014

Re: Problem with two identical conceal arguments in the same line

On Do, 06 Feb 2014, tjg wrote:

> I write and I wish to insert (and then hide) remarks on what I am writing.
> So, I tried to become familiar with conceal and came up with the following
> lines of code :
>
> - in my .vimrc :
> set conceallevel=2
>
> - in my syntax.vim :
> syntax match Remark « •R: .*•" conceal containedin=ALL cchar=•
> highlight Remark ctermfg=Blue
>
> But I have encountered a (I suppose foreseeable) problem.
> If I write a sentence such as :
>
> Once upon a time •R: find another incipit•, there was a king •R: replace by
> tycoon• who etc… etc…
>
> The problem is that :
>
> - when the cursor is on that specific line, everything is blue after time
> (not included) and before who (ditto).
> - when the cursor is on another line, the fragment "there was a king"
> disappears
>
> What did I do wrong ?

Your pattern is too greedy, e.g. your first match will select everything
(.*) until the final and last •
There are two ways around that, either use the non-greedy quantifier '\{-}':
syntax match Remark "•R: .\{-}" conceal containedin=ALL cchar=•

or match all characters except '•'
syntax match Remark "•R: [^•]*" conceal containedin=ALL cchar=•

Personally I like the second method better, because it is more explicit
and it is not always easy to understand, what the non-greedy variants
will match, it might be actually too less.

Best,
Christian
--

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment