vim9script userdef

25 views
Skip to first unread message

N i c o l a s

unread,
Dec 10, 2022, 7:45:34 AM12/10/22
to vim_use
Hi,

In vim9script, is it possible to write the equivalent of this legacy vimscript code :

let defdict[type] = g:tagbar_type_{type}

For instant it results to E488: Trailing characters: {ftype}

Thank you
Nicolas

Marc Chantreux

unread,
Dec 10, 2022, 9:02:35 AM12/10/22
to vim...@googlegroups.com
hello,

> let defdict[type] = g:tagbar_type_{type}

is this ok for you?

let type ="grep"
exec $"let defdict[type] = g:gitgutter_{type}"

regards
marc

N i c o l a s

unread,
Dec 10, 2022, 9:17:52 AM12/10/22
to vim_use
Hi Marc, 

  • Not it is not OK. E488 when i try to port autoload/tagbar.vim lin386

function! s:LoadUserTypeDefs(...) abort
     if a:0 > 0
         let type = a:1
 
         let defdict = {}
         let defdict[type] = g:tagbar_type_{type}

N i c o l a s

unread,
Dec 10, 2022, 9:23:08 AM12/10/22
to vim_use
Port in vim9script, do i have to pass by exécutable command as you de scribe it ? 

Thank you Marc

Salman Halim

unread,
Dec 10, 2022, 1:07:50 PM12/10/22
to vim...@googlegroups.com
On Sat, Dec 10, 2022 at 9:23 AM N i c o l a s <niva...@gmail.com> wrote:
Port in vim9script, do i have to pass by exécutable command as you de scribe it ? 

Thank you Marc

Le samedi 10 décembre 2022 à 15:17:52 UTC+1, N i c o l a s a écrit :
         let defdict[type] = g:tagbar_type_{type}


Maybe you could try prefixing the command with 'legacy', but I think you might have better success with just replacing g:tagbar_type_{type} flavour variables with just a dict called g:tagbar_type and then 'type' could just be a key: g:tagbar_type[type], much like you have with defdict on that same line. I haven't looked at the actual source, so I can't speak to whether this will cause other problems, but this is something I've had success with in my own scripts.

N i c o l a s

unread,
Dec 11, 2022, 4:14:28 AM12/11/22
to vim_use
Thank you Salman, your advise seems to match what I need. In Progress... :)

Mike

unread,
Dec 11, 2022, 10:00:13 AM12/11/22
to vim...@googlegroups.com
On 12/10/2022 9:17 AM, N i c o l a s wrote:
> Hi Marc,
>
>
> - Not it is not OK. E488 when i try to port autoload/tagbar.vim lin386
>
> https://github.com/preservim/tagbar/blob/master/autoload/tagbar.vim
>
> function! s:LoadUserTypeDefs(...) abort
> if a:0 > 0
> let type = a:1
>
> let defdict = {}
> let defdict[type] = g:tagbar_type_{type}

Curly-brace names are not supported in Vim9. This is documented in both
:help vim9-differences
and
:help curly-brace-names

N i c o l a s

unread,
Dec 11, 2022, 11:08:19 AM12/11/22
to vim_use
Thank you Mike. That's why i'm trying to apply what Salman said

'' 
just a dict called g:tagbar_type and then 'type' could just be a key '' 

Thank you
Nicolas 
Reply all
Reply to author
Forward
0 new messages