On 11/11/08 14:41, Ben Schmidt wrote:
> Do you know about local mappings? You can use them to make mappings that
> only work in a single buffer, so you could use autocommands to define
> such mappings per filetype and you wouldn't need to call a function to
> change them: just moving your cursor into the appropriate window would
> activate all the mappings for that filetype.
>
> :help map-local
>
> I don't think it sounds completely like what you want, but it's
> something to be aware of.
>
> Ben.

Yes, this is what I would call the "official" or "recommended" way to do 
this sort of things:

First create an after-plugin for each filetype you're interested in. On 
Windows, this will be ~/vimfiles/after/ftplugin/<filetype>.vim or on 
Unix ~/.vim/after/ftplugin/<filetype>.vim (replacing, of course, 
<filetype> by the filetype). Create the directories if they don't exist yet.

If you want to map your keys to functions, define (in those after-plugin 
scripts) script-local functions, so functions in one script (for one 
filetype) won't override those in another script (for another filetype):

        function <SID>FooBarBaz()
        " ...
        endfunction

Then create your local mappings, calling the script-local functions:

        map   <buffer>   <F5>   :call <SID>FooBarBaz()<CR>

The string <SID> will be replaced by the script-identifier (maybe 
<SNR>19_ or somesuch), so that Vim will know which script-local function 
(from which script) to use when you invoke the mapping. <buffer> in the 
mappings makes the mapping "buffer-local" so you can have F5 do one 
thing when in, let's say, a Vim script, and a totally different thing 
when in, let's say, a C program.

You can also, for instance, set options in those same after-plugins. Be 
sure to use ":setlocal" rather than ":set".


Best regards,
Tony.
-- 
A diva who specializes in risqué arias is an off-coloratura soprano ...

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

Reply via email to