Prepending an string option

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Prepending an string option

Anton Shepelev
Hello, all

How can one prepend a Vim string option?  I need to prepent
formatlistpat for Markdown.  I have tried to combine `set'
and `execute()', but to no avail.  `execute()' is documented
as returning the command output as a string, yet I can't
seem to call it as a function and use the return value in
`set':

  set formatlistpat=prepend|execute('set formatlistpat?')

Also I fear I will lose escapes this way.  Is it possible to
preserve them?

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200817133330.5130b92b6df0c50799fcea8a%40gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: Prepending an string option

Gary Johnson-4
On 2020-08-17, Anton Shepelev wrote:

> Hello, all
>
> How can one prepend a Vim string option?  I need to prepent
> formatlistpat for Markdown.  I have tried to combine `set'
> and `execute()', but to no avail.  `execute()' is documented
> as returning the command output as a string, yet I can't
> seem to call it as a function and use the return value in
> `set':
>
>   set formatlistpat=prepend|execute('set formatlistpat?')
>
> Also I fear I will lose escapes this way.  Is it possible to
> preserve them?

Here are a couple of ways to do that.

    :execute 'set formatlistpat=' . 'patternprefix' . &formatlistpat

    :let &formatlist = 'patternprefix' . &formatlist

where patternprefix is the string you wish to prepend to
'formatlistpat'.

See:

    :help :execute
    :help :let-option

Note that 'formatlistpat' is a single pattern, not a list of
patterns, so you would not use :set^= to prepend a list element to
it.  If interested anyway, see:

    :set^=

HTH,
Gary

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200817145035.GC20476%40phoenix.
Reply | Threaded
Open this post in threaded view
|

Re: Prepending an string option

Gary Johnson-4
On 2020-08-17, Gary Johnson wrote:

> On 2020-08-17, Anton Shepelev wrote:
> > Hello, all
> >
> > How can one prepend a Vim string option?  I need to prepent
> > formatlistpat for Markdown.  I have tried to combine `set'
> > and `execute()', but to no avail.  `execute()' is documented
> > as returning the command output as a string, yet I can't
> > seem to call it as a function and use the return value in
> > `set':
> >
> >   set formatlistpat=prepend|execute('set formatlistpat?')
> >
> > Also I fear I will lose escapes this way.  Is it possible to
> > preserve them?
>
> Here are a couple of ways to do that.
>
>     :execute 'set formatlistpat=' . 'patternprefix' . &formatlistpat
>
>     :let &formatlist = 'patternprefix' . &formatlist

Oops.  That second example should of course be:

    :let &formatlistpat = 'patternprefix' . &formatlistpat

>
> where patternprefix is the string you wish to prepend to
> 'formatlistpat'.
>
> See:
>
>     :help :execute
>     :help :let-option
>
> Note that 'formatlistpat' is a single pattern, not a list of
> patterns, so you would not use :set^= to prepend a list element to
> it.  If interested anyway, see:
>
>     :set^=

HTH better,
Gary

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200817145637.GD20476%40phoenix.
Reply | Threaded
Open this post in threaded view
|

Re: Prepending an string option

Anton Shepelev
Gary Johnson to Anton Shepelev:

> > How can one prepend a Vim string option?
> > [...]
>
> Here are a couple of ways to do that.
>
>   :execute 'set formatlistpat=' . 'patternprefix' . &formatlistpat
>
>   :let &formatlist = 'patternprefix' . &formatlist
>
> where patternprefix is the string you wish to prepend to
> 'formatlistpat'.
> [...]

Thank you very much, Gary.  Time for me to learn Vimscript.

--
--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200818132236.32431a74f762afd7bcd4e614%40gmail.com.