Friday, October 10, 2014

Re: How to use <script> attribute in map command?

On Friday, October 10, 2014 12:55:08 PM UTC+2, glts wrote:
> Hi,
>
> On Friday, October 10, 2014 12:04:17 PM UTC+2, jiaxing_wang wrote:
> > This wiki page:
> >
> > http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)
> >
> >
> >
> >
> > says with the following maps in a script file:
> >
> >
> > nnoremap \x /Topic
> > nmap <script> ,f \x<CR>
> >
> >
> > "In the second map command, ',f' is mapped to invoke \x which is replaced with '/Topic'.
> >
> > If the user or some other plugin has defined a mapping for '\x', then it is not used by ',f'."
> >
> >
> >
> > But I tried and find '\x' is not remapped to '/Topic' as the wiki says, so what does <script>
> >
> > really mean and how to use it?
>
> Unfortunately the wiki example is wrong.
>
> Here's a short script that uses a mapping with <script>.
>
> function! s:SayHelloToUser() abort
> echo printf("Hello %s!", $USER)
> endfunction
>
> nmap <script> <Plug>SayHello :<C-U>call <SID>SayHelloToUser()<CR>
>
> The <Plug> mapping is the hook that a user can map to, eg by defining
>
> nmap <Leader>h <Plug>SayHello
>
> In the <Plug> mapping, <script> ensures that the right-hand side of the
> mapping will never be affected by user-defined mappings.
>
> For example, if <script> were missing and somebody had defined a
> command-line mode mapping for the character sequence 'cal', then the
> mapping will likely fail because 'cal' is mapped to whatever the user
> mapped it to. <script> protects from such disruptions.

My example is a bit poor though, since in this case you might as well
just use :nnoremap to be safe from side-effects. But I hope I got the
point across.

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

No comments: