Loading ...
Sorry, an error occurred while loading the content.
 

Re: What keystrokes called a function

Expand Messages
  • Wind
    Hello David, A secret is that map command maps one key sequence to another, so you aa sequence will be translated to call Test (this will try to start
    Message 1 of 4 , Mar 2, 2005
      Hello David,
      A secret is that map command maps one key sequence to another,
      so you "\aa" sequence will be translated to "call Test" (this
      will try to start change command ("c" in normal mode) and fail
      'couse there is no object "al"), so to fix it use:

      nnoremap \aa :call Test()<CR>

      ":" will start a command line mode
      and <CR> will be replaced with Enter key stroke.
      This way it will work.


      Wednesday, March 2, 2005, 6:15:37 AM, you wrote:


      DF> Apologies if this double posts.

      DF> Vim 6.3.60 WinXP

      DF> If I create a function called Test and create a mapping for it:
      DF> nnoremap \aa call Test()

      DF> Is there anyway from within the function to know what key combination
      DF> invoked it?

      DF> In my plugin I want the user to create their own mappings to my functions.
      DF> But I also need to pass the "real" key sequence to Vim.

      DF> So if they did this:
      DF> nnoremap yy call Test()

      DF> In my function I want to issue:
      DF> exec 'normal! yy'

      DF> When they create the mapping, they could do something like this:
      DF> nnoremap yy call Test('yy')

      DF> But I was hoping to make this more user friendly and less error prone.

      DF> TIA,
      DF> Dave




      --
      Best regards,
      Wind mailto:sonic_wind@...
    • hermitte@free.fr
      Hello, ... May be you can provide a command of your own. The command will be used in ... The command will delegate its work to an internal function, which will
      Message 2 of 4 , Mar 2, 2005
        Hello,

        David Fishburn <fishburn@...> wrote:

        > If I create a function called Test and create a mapping for it:
        > nnoremap \aa call Test()
        >
        > Is there anyway from within the function to know what key combination
        > invoked it?
        >
        > In my plugin I want the user to create their own mappings to my functions.
        > But I also need to pass the "real" key sequence to Vim.
        >
        > So if they did this:
        > nnoremap yy call Test()
        >
        > In my function I want to issue:
        > exec 'normal! yy'
        >
        > When they create the mapping, they could do something like this:
        > nnoremap yy call Test('yy')
        >
        > But I was hoping to make this more user friendly and less error prone.

        May be you can provide a command of your own. The command will be used in
        the following way:
        :MyNNoreMap yy :call Test()<cr>
        :MyINoreMap zz <esc>j:call F()<cr>:call Test2()<cr>

        The command will delegate its work to an internal function, which will
        recognize the functions defined by your plugin, and add as a last
        parameter the keybinding from the mapping, before doing a :map.

        There is a problem with this approach: the mappings your end-user will
        define can not use local functions. i.e.
        function s:Foo()
        echo "foo"
        endfunction
        :MyNNoreMap yy :call <sid>Foo()<cr>:call Test()<cr>
        won't work.

        HTH,

        --
        Luc Hermitte
      • Johnny Blaze
        On Tue, 1 Mar 2005 23:15:37 -0500, David Fishburn ... com! -nargs=* BindTest call Bind( ) fun! Bind(keys) exec nnoremap . a:keys . :call
        Message 3 of 4 , Mar 4, 2005
          On Tue, 1 Mar 2005 23:15:37 -0500, David Fishburn
          <fishburn@...> wrote:
          >
          > Apologies if this double posts.
          >
          > Vim 6.3.60 WinXP
          >
          > If I create a function called Test and create a mapping for it:
          > nnoremap \aa call Test()
          >
          > Is there anyway from within the function to know what key combination
          > invoked it?
          >
          > In my plugin I want the user to create their own mappings to my functions.
          > But I also need to pass the "real" key sequence to Vim.
          >
          > So if they did this:
          > nnoremap yy call Test()
          >
          > In my function I want to issue:
          > exec 'normal! yy'
          >
          > When they create the mapping, they could do something like this:
          > nnoremap yy call Test('yy')
          >
          > But I was hoping to make this more user friendly and less error prone.
          >

          com! -nargs=* BindTest call <SID>Bind(<f-args>)

          fun! Bind(keys)
          exec "nnoremap " . a:keys . " :call <SID>Test()<CR>"
          " anything else with a:keys
          endfun


          So the user:
          :BindTest yy

          --

          . o O pyromancer O o .
        Your message has been successfully submitted and would be delivered to recipients shortly.