On 12/10/09 23:11, Bram Moolenaar wrote:
>
>
> Michael Henry wrote:
>
>>>> I'd like to advocate the deprecation of the use of :vmap
>>>> command [...] This leads to unintended interference with
>>>> Select mode's defined behavior, which is especially
>>>> noticeable with "snippets" plugins (such as UltiSnips) that
>>>> use select mode extensively.
>>
>>> Did you read  :help Select-mode-mapping  ?
>>> When a :vmap is used in Select mode Vim temporarily switches
>>> to Visual mode.   Quite often this works as expected.
>>
>> Yes, I read that section of the help.  For those cases where a
>> :vmap is appropriate, Vim's switching from Select mode to Visual
>> mode does indeed ensure things work as expected, such that a
>> single right-hand side works for both Visual and Select modes.
>> I think it's OK to have Select-mode mappings for non-printable
>> characters, in which case :vmap could be appropriate (such as
>> for mapping CTRL-C to copy to the clipboard).
>>
>> However, I'm advocating that :vmap should not be used to map
>> printable characters, as it interferes with the user's
>> fundamental expectations of Select-mode behavior.  Select mode
>> and Visual mode are different and have different purposes, so
>> it's reasonable that they might not always have the same
>> mappings.
>>
>> For example, the popular matchit plugin uses :vnoremap as
>> follows:
>>
>> vnoremap<silent>  %  :<C-U>call<SID>Match_wrapper('',1,'v')<CR>m'gv``
>>
>> This has the undesirable effect of creating a Select-mode
>> mapping for the "%" character, which breaks the user's
>> expectation that pressing "%" should delete the selection and
>> insert a "%" character.
>>
>> For plugins like UltiSnips, the user is prompted with some
>> default text highlighted in Select mode.  If the user presses
>> <Tab>, the text is kept and the cursor jumps to the next
>> "tabstop"; to override the default text, the user simply types
>> the new text.  This works well unless printable characters are
>> mapped in Select mode, in which case the user can end up quite
>> surprised (for example, by pressing "%" and finding that the
>> cursor has jumped unexpectedly due to the matchit plugin's
>> Select-mode mapping).
>>
>> I'm proposing that the documentation make a strong statement
>> deprecating the use of :vmap for printable characters (and only
>> printable characters).  The statement would need to carefully
>> explain the negative effects of :vmap with printable characters,
>> and contrast this with appropriate use cases for :vmap.
>
> OK, now I get your remark.  I first thought you were complaining that
> the mapping didn't work.  The problem actually is that the mapping does
> work, which is unexpected in Select mode.
>
> Let's add a note:
>
>                                               *mapmode-x* *mapmode-s*
> Some commands work both in Visual and Select mode, some in only one.  Note
> that quite often "Visual" is mentioned where both Visual and Select mode
> apply. |Select-mode-mapping|
> NOTE: Mapping a printable character in Select mode may confuse the user.  It's
> better to explicitly use :xmap and :smap for printable characters.
>
>
> Perhaps you can go over all existing plugins that use :vmap and ask them
> to change to :xmap where needed.
>

I don't know why Michel's reply above ended up in my general inbox 
instead of my Vim inbox but it caused me to read this thread earlier 
than I would have otherwise.

I shall add (to Bram's remark above) that the :xmap and :smap commands 
(and also ::xmenu and :smenu) are relatively recent (previously there 
were only :vmap and :vmenu) so it is possible that plugins which existed 
prior to their introduction have not yet been updated.

Where plugins, especially ones not part of the Vim distribution, still 
use :vmap or :vmenu, it would probably be better to wrap any change in 
"if exists(':xmap') == 2" or in "if exists(':xmenu') == 2" to avoid 
unexpected errors in older versions of Vim.

This may apply even to the matchit plugin (which is distributed with Vim 
but requires user action to become enabled), unless the version in the 
appropriate $VIMRUNTIME tree for the current Vim is invoked by the line

        runtime macros/matchit vim

in a one-line plugin named one of

        $VIM/vimfiles/plugin/matchit.vim        (on any platform)
        $HOME/vimfiles/plugin/matchit.vim       (on Windows etc.)
        $HOME/.vim/plugin/matchit.vim           (on Unix etc.)


Best regards,
Tony.
-- 
Love cannot be much younger than the lust for murder.
                -- Sigmund Freud

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

Reply via email to