Prepending an string option

13 views
Skip to first unread message

Anton Shepelev

unread,
Aug 17, 2020, 6:33:43 AM8/17/20
to vim...@googlegroups.com
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?

Gary Johnson

unread,
Aug 17, 2020, 10:52:38 AM8/17/20
to vim...@googlegroups.com
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

Gary Johnson

unread,
Aug 17, 2020, 10:58:37 AM8/17/20
to vim...@googlegroups.com
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

Anton Shepelev

unread,
Aug 18, 2020, 6:22:51 AM8/18/20
to vim...@googlegroups.com
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.

Reply all
Reply to author
Forward
0 new messages