Re: Vim 9 script question

Eric Marceau <[email protected]> Fri, 13 Jun 2025 15:59:32 -0400
Newsgroups gmane.editors.vim
Message-ID <[email protected]>
Hello Lang Chiang,

Good to hear your problem is solved!

Could you share with all of us

  * exactly where the problem's root cause was, and
  * the how of way it was resolved?

I am sure that would benefit many of us.

Thank you,


Eric


On 2025-06-12 05:16, Yu Lang Chiang wrote:
> I've identified that the root cause was in another part of the code, 
> and it's now resolved. Thank you all for your assistance.
>
> Salman Halim <[email protected]> 於 2025年6月11日 週三 下午8:45寫道:
>
>     Use .. in Vim 9 (mappings 2 and 3 below). Also, you have v.count
>     and v:count. They probably aren't both correct (all of them have
>     that).
>
>     What happens when you just type the whole thing on the command
>     line directly?
>
>     Salman
>
>     On Wed, Jun 11, 2025, 08:21 Yu Lang Chiang <[email protected]>
>     wrote:
>
>         I tried the following combinations:
>
>         <C-U>exe "" . (v.count ? v:count : "") . "bprevious"<CR>
>         <C-U>exe "” .. (v.count ? v:count : "") .. "bprevious"<CR>
>         <C-U>execute "” .. (v.count ? v:count : "") .. "bprevious"<CR>
>         <C-U>execute "” . (v.count ? v:count : "") . "bprevious"<CR>
>
>
>         None of them work.
>
>         Vim has been updated to version 9.1.1435
>
>>         Maxim Kim <[email protected]> 於 2025年6月11日 上午11:05 寫道:
>>
>>         vim9script enforces spaces between operators,  your mappings
>>         are defined in vim9script context so it expects spaces
>>         between concatenation operator .
>>
>>         :<C-U>exe "" . (v.count ? v:count : "") . "bprevious"<CR>
>>
>>         On Tuesday, June 3, 2025 at 4:45:56 PM UTC+10 Yu Lang Chiang
>>         wrote:
>>
>>             Recently I've been trying to learn Vim 9 script by
>>             rewriting Vim plugins into Vim 9 script. While attempting
>>             to modify *vim-unimpaired*, I discovered that functions
>>             related to setting up mappings do not work properly when
>>             ported to Vim 9 script. For example, in the
>>             `plugin/unimpaired.vim` file, the function
>>             `MapNextFamilty` is problematic.
>>
>>             **Original version:**
>>
>>             ```vim
>>             execute 'nnoremap <silent> '.prefix.'previous) :<C-U>exe
>>             "'.cmd.'previous'.end
>>             execute 'nnoremap <silent> '.prefix.'next)     :<C-U>exe
>>             "'.cmd.'next'.end
>>             execute 'nnoremap '.prefix.'first)  :<C-U><C-R>=v:count ?
>>             v:count . "' . a:current . '" : "' . a:cmd .
>>             'first"<CR><CR>' . zv
>>             execute 'nnoremap '.prefix.'last) :<C-U><C-R>=v:count ?
>>             v:count . "' . a:current . '" : "' . a:cmd .
>>             'last"<CR><CR>' . zv
>>             execute 'nnoremap <silent> '.map.'Previous :<C-U>exe
>>             "'.cmd.'previous'.end
>>             execute 'nnoremap <silent> '.map.'Next     :<C-U>exe
>>             "'.cmd.'next'.end
>>             execute 'nnoremap <silent> '.map.'First    :<C-U>exe
>>             "'.cmd.'first'.end
>>             execute 'nnoremap <silent> '.map.'Last     a:<C-U>exe
>>             "'.cmd.'last'.end
>>             ```
>>
>>             **Vim 9 script version:**
>>
>>             ```vim
>>             execute 'nnoremap <silent> ' .. prefix .. 'previous)
>>             :<C-U>exe "' .. tcmd .. 'previous' .. end
>>             execute 'nnoremap <silent> ' .. prefix .. 'next)    
>>             :<C-U>exe "' .. tcmd .. 'next' .. end
>>             execute 'nnoremap ' .. prefix .. 'first)
>>              :<C-U><C-R>=v:count ? v:count . "' .. current .. '" : "'
>>             .. cmd .. 'first"<CR><CR>' .. zv
>>             execute 'nnoremap ' .. prefix .. 'last)
>>             :<C-U><C-R>=v:count ? v:count . "' .. current .. '" : "'
>>             .. cmd .. 'last"<CR><CR>' .. zv
>>             execute 'nnoremap <silent> ' .. tmap .. 'Previous
>>             :<C-U>exe "' .. tcmd .. 'previous' .. end
>>             execute 'nnoremap <silent> ' .. tmap .. 'Next    
>>             :<C-U>exe "' .. tcmd .. 'next' .. end
>>             execute 'nnoremap <silent> ' .. tmap .. 'First  
>>              :<C-U>exe "' .. tcmd .. 'first' .. end
>>             execute 'nnoremap <silent> ' .. tmap .. 'Last    
>>             :<C-U>exe "' .. tcmd .. 'last' .. end
>>             ```
>>
>>             When inspecting the mappings using:
>>
>>             ```vim
>>             echo maparg('<Plug>('unimpaired-commmand')', 'n')
>>             ```
>>
>>             you find that both versions produce identical mappings.
>>             For example:
>>
>>             - **Original version:**
>>
>>             ```
>>             :<C-U>exe "".(v.count ? v:count : "")."bprevious"<CR>
>>             ```
>>
>>             - **Vim 9 script version:**
>>
>>             ```
>>             :<C-U>exe "".(v.count ? v:count : "")."bprevious"<CR>
>>             ```
>>
>>             Despite the mappings appearing the same, the one defined
>>             in the Vim 9 script version does not work. Even after
>>             removing `<silent>`, no error messages are reported. Any
>>             advice?
>>
>>             **Test Environment:**
>>
>>             - **OS:** Fedora Linux 42 (x86-64)
>>             - **Vim:** 9.1.1418
>>
>>             My repository
>>             ishttps://github.com/seanexplus/vim-unimpaired/tree/master.
>>             All vim 9 script rewriting is in vim-9-test branch.
>>
>>
>>         --
>>         --
>>         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, visithttp://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 [email protected].
>>         To view this discussion
>>         visithttps://groups.google.com/d/msgid/vim_use/98ea42d5-faba-46f9-b642-f1c82d957d71n%40googlegroups.com
>>         <https://groups.google.com/d/msgid/vim_use/98ea42d5-faba-46f9-b642-f1c82d957d71n%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>         -- 
>         -- 
>         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 [email protected].
>         To view this discussion visit
>         https://groups.google.com/d/msgid/vim_use/0C87B90E-C27A-466E-B58E-60A4A837C3B4%40gmail.com
>         <https://groups.google.com/d/msgid/vim_use/0C87B90E-C27A-466E-B58E-60A4A837C3B4%40gmail.com?utm_medium=email&utm_source=footer>.
>
>     -- 
>     -- 
>     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 [email protected].
>     To view this discussion visit
>     https://groups.google.com/d/msgid/vim_use/CANuxnEdyMUNHo5ZEBmV_JJm338GtjwpKMSpb6aXOfLb2DApDiw%40mail.gmail.com
>     <https://groups.google.com/d/msgid/vim_use/CANuxnEdyMUNHo5ZEBmV_JJm338GtjwpKMSpb6aXOfLb2DApDiw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>
> -- 
> -- 
> 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 [email protected].
> To view this discussion visit 
> https://groups.google.com/d/msgid/vim_use/CALZ2XgjzgUjmDeHC%3D2TJUyYzg1zfKx%2BdzAy84FRZFZjPv%3DThjA%40mail.gmail.com 
> <https://groups.google.com/d/msgid/vim_use/CALZ2XgjzgUjmDeHC%3D2TJUyYzg1zfKx%2BdzAy84FRZFZjPv%3DThjA%40mail.gmail.com?utm_medium=email&utm_source=footer>.

-- 
-- 
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 [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_use/ebddda58-8512-4a64-9236-738bb25157ee%40gmail.com.