Monday, August 17, 2020

Re: Prepending an string option

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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200817145035.GC20476%40phoenix.

No comments:

Post a Comment