Quantcast

Why the substitute in the selection only substitute the first letter in the selection in my vimscript?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why the substitute in the selection only substitute the first letter in the selection in my vimscript?

Zhe Lee
Why the substitute in the selection only substitute the first letter in the selection?

The \%V option works fine when I just use the command line to exec it.

But it seems not work very well when I use it in the vimscript.

vnoremap <leader>dfc :call DragonflyCmdProcess(1)<CR>

function! DragonflyCmdProcess(visual)
    if a:visual
        normal! gv
        " execute "s/\\%V./&,/g"
        execute "'<,'>s/\\%Ve/x/g"
    else
endfunction

--
--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why the substitute in the selection only substitute the first letter in the selection in my vimscript?

Christian Brabandt
Hi Zhe!

On Fr, 27 Jan 2017, Zhe Lee wrote:

> Why the substitute in the selection only substitute the first letter in the selection?
>
> The \%V option works fine when I just use the command line to exec it.
>
> But it seems not work very well when I use it in the vimscript.
>
> vnoremap <leader>dfc :call DragonflyCmdProcess(1)<CR>
>
> function! DragonflyCmdProcess(visual)
>     if a:visual
>         normal! gv
>         " execute "s/\\%V./&,/g"
>         execute "'<,'>s/\\%Ve/x/g"
>     else
> endfunction

I am not sure, I understand. Please try with the following changes:

vnoremap <leader>dfc :<c-u>call DragonflyCmdProcess(1)<CR>
function! DragonflyCmdProcess(visual)
    if a:visual
        '<,'>s/\%Ve/x/g
    endif
endfunction


Best,
Christian
--
Amerikaner werden mißtrauisch, wenn man nicht einer von ihnen werden
will - im Gegensatz zu Franzosen, Engländern, Schweden und den meisten
anderen Völkern, die es gerade mißtrauisch macht, wenn man zu ihnen
gehören möchte.
                -- Billy Wilder

--
--
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].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why the substitute in the selection only substitute the first letter in the selection in my vimscript?

Zhe Lee
On Friday, January 27, 2017 at 9:17:06 PM UTC+8, Christian Brabandt wrote:

> Hi Zhe!
>
> On Fr, 27 Jan 2017, Zhe Lee wrote:
>
> > Why the substitute in the selection only substitute the first letter in the selection?
> >
> > The \%V option works fine when I just use the command line to exec it.
> >
> > But it seems not work very well when I use it in the vimscript.
> >
> > vnoremap <leader>dfc :call DragonflyCmdProcess(1)<CR>
> >
> > function! DragonflyCmdProcess(visual)
> >     if a:visual
> >         normal! gv
> >         " execute "s/\\%V./&,/g"
> >         execute "'<,'>s/\\%Ve/x/g"
> >     else
> > endfunction
>
> I am not sure, I understand. Please try with the following changes:
>
> vnoremap <leader>dfc :<c-u>call DragonflyCmdProcess(1)<CR>
> function! DragonflyCmdProcess(visual)
>     if a:visual
>         '<,'>s/\%Ve/x/g
>     endif
> endfunction
>
>
> Best,
> Christian
> --
> Amerikaner werden mißtrauisch, wenn man nicht einer von ihnen werden
> will - im Gegensatz zu Franzosen, Engländern, Schweden und den meisten
> anderen Völkern, die es gerade mißtrauisch macht, wenn man zu ihnen
> gehören möchte.
> -- Billy Wilder
add a more backslash will work thnx`
function! DragonflyCmdProcess(visual)
    if a:visual
        '<,'>s/\\%Ve/x/g
    endif
endfunction

--
--
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].
For more options, visit https://groups.google.com/d/optout.
Loading...