On 12/11/08 00:24, Ben Schmidt wrote:
>> The improved approach is to use  s:SetAltMaps() functions (instead of
>> SetAltMaps()) with the local maps you mentioned earlier:
>>
>> map <buffer>  <F12>    :call <SID>SetAltMaps()<CR>
>> map <buffer>  <C-F12>  :call <SID>ResetMaps()<CR>
>>
>> with those maps also residing in .vim/ftplugin/FILETYPE.vim files.
>> That way neither the functions nor the maps occupy global namespace.
>
> Absolutely. One thing to note with this approach though, is that you
> can't (well, you can, but it's difficult) call the function from outside
> the scope of the script. It's unclear to me whether the OP wants to do
> this. Obviously if just using maps like above it's fine; likewise you
> can make it work with autocommands defined in the script.
>
> Ben.

A function defined with <SID> at the start of its name can be invoked 
from a mapping defined in the same script, <SID> will be replaced by the 
script ID (e.g. <SNR>35_ if this is the 35th script sourced in this Vim 
session). The mapping can then be invoked from anywhere, unless of 
course it is defined with <buffer>, which makes it local to the buffer 
which was being edited when the mapping was defined.

If you don't use <SID> or s: when defining a function, it is global, and 
can be invoked from anywhere, even by typing its name in a ":call" 
statement at the command-line. In that case it is better to give the 
function a distinctive name (maybe a name starting with the name of the 
script where it was defined), in order to avoid clashes.


Best regards,
Tony.
-- 
Toilet Toupee, n.:
        Any shag carpet that causes the lid to become top-heavy, thus
creating endless annoyance to male users.
                -- Rich Hall, "Sniglets"

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to