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

[Scripting] The mapping problem

Expand Messages
  • Preben Randhol
    Hi I have now come to the part of my script where I ll start adding mappings. The number of very useful scripts on vim.sf.net rises more or less exponentially
    Message 1 of 7 , Oct 28, 2002
    • 0 Attachment
      Hi

      I have now come to the part of my script where I'll start adding
      mappings. The number of very useful scripts on vim.sf.net rises more
      or less exponentially at vim.sf.net, thanks all of you! There is however
      a problem too and that is mappings. Some scripts are clean and it is
      easy to find the mappings others can be rather messy.

      My questions are:

      1. Would it be better if script had a separate file for the keybindings
      so that it is easier to modify it to ones personal liking (and to
      avoid colliding mappings)? Then it would be easier to update the
      scripts as new versions come without having to do all the
      modifications each time.

      2. Can one define a <ScriptLocal> which one can easily modify to be say:
      <Leader>m or <Leader>k etc... for the script so that all the mappings
      in the script start with the same keybindings. Thus make it easier to
      avoid colliding mappings?

      Example I might like to have \m for all mail-related mappings \a for
      Ada mappings, \p for project mappings etc..

      3. Perhaps one should think of making a Vim Scripting Style Guide?

      And a final plea to all you out there that makes scripts. Please put
      more info/help into the script source. The problem is that many script
      only have info/help on vim.sf.net. So that if you have downloaded a
      script it is easy to find the same info as one find on the script page
      of vim.sf.net. Especially how to install the script and a list of the
      mappings, so that one can fast determine how to use the script.
      Also put a bit more comments and "air" in the scripts so they are easier
      to read. One do not need to do all in one line. :-)

      Thanks in advance

      Regards,
      Preben Randhol

      --
      Preben Randhol ---------------- http://www.pvv.org/~randhol/ --
      Just vim it.
    • Dan Sharp
      ... Take a look at :he write-plugin for some examples of what to do. The following example is a pared down version of that text. In your plugin, you would
      Message 2 of 7 , Oct 28, 2002
      • 0 Attachment
        >From: Preben Randhol <randhol+vim@...>
        >
        >1. Would it be better if script had a separate file for the keybindings
        > so that it is easier to modify it to ones personal liking (and to
        > avoid colliding mappings)? Then it would be easier to update the
        > scripts as new versions come without having to do all the
        > modifications each time.

        Take a look at :he write-plugin for some examples of what to do. The
        following example is a pared down version of that text.

        In your plugin, you would create a mapping

        noremap <script> <Plug>TypecorrAdd :call <SID>Add()<CR>

        This creates a kind of external interface from your plugin that can be
        utilized in a .vimrc file. Now, in your plugin, the construction

        if !hasmapto('<Plug>TypecorrAdd')
        map <unique> <Leader>a <Plug>TypecorrAdd
        endif

        will let you define a default mapping to call your function. If someone
        wants to override that mapping, they can put a line in their .vimrc like

        map <Leader>b <Plug>TypecorrAdd

        and so when your plugin is loaded, your default mapping will not be used
        because the user's mapping has already been defined and will be used
        instead. Also, since this mapping would be in their .vimrc, there is no
        need for them to edit your plugin file, so they won't lose anything when
        upgrading to a new version.


        >2. Can one define a <ScriptLocal> which one can easily modify to be
        >say:
        > <Leader>m or <Leader>k etc... for the script so that all the
        >mappings in the script start with the same keybindings. Thus make it
        >easier to avoid colliding mappings?
        >
        > Example I might like to have \m for all mail-related mappings \a for
        > Ada mappings, \p for project mappings etc..

        <LocalLeader> is the buffer-local analogue to <Leader>. You can do:

        let maplocalleader='\a'
        :map <LocalLeader>m :echo "It is morning!"<CR>

        then typing \am will do the echo. You could create a filetype plugin for
        each filetype you want that defines maplocalleader to be whatever prefix you
        choose.

        Dan Sharp

        _________________________________________________________________
        Get faster connections�-- switch to�MSN Internet Access!
        http://resourcecenter.msn.com/access/plans/default.asp
      • Preben Randhol
        ... Thanks ... I see thanks Preben -- Preben Randhol ---------------- http://www.pvv.org/~randhol/ -- Just vim it.
        Message 3 of 7 , Oct 30, 2002
        • 0 Attachment
          Dan Sharp <dwsharp@...> wrote on 30/10/2002 (11:45) :
          > Take a look at :he write-plugin for some examples of what to do. The
          > following example is a pared down version of that text.
          >
          > In your plugin, you would create a mapping
          >
          > noremap <script> <Plug>TypecorrAdd :call <SID>Add()<CR>
          >
          > This creates a kind of external interface from your plugin that can be
          > utilized in a .vimrc file. Now, in your plugin, the construction
          >
          > if !hasmapto('<Plug>TypecorrAdd')
          > map <unique> <Leader>a <Plug>TypecorrAdd
          > endif

          Thanks

          > <LocalLeader> is the buffer-local analogue to <Leader>. You can do:
          >
          > let maplocalleader='\a'
          > :map <LocalLeader>m :echo "It is morning!"<CR>

          I see thanks

          Preben
          --
          Preben Randhol ---------------- http://www.pvv.org/~randhol/ --
          Just vim it.
        • Benji Fisher
          ... Large, complicated scripts with lots of options may want to use a separate file for defining mappings and other options. I proposed one mechanism for
          Message 4 of 7 , Nov 2, 2002
          • 0 Attachment
            Preben Randhol wrote:
            >
            > Hi
            >
            > I have now come to the part of my script where I'll start adding
            > mappings. The number of very useful scripts on vim.sf.net rises more
            > or less exponentially at vim.sf.net, thanks all of you! There is however
            > a problem too and that is mappings. Some scripts are clean and it is
            > easy to find the mappings others can be rather messy.
            >
            > My questions are:
            >
            > 1. Would it be better if script had a separate file for the keybindings
            > so that it is easier to modify it to ones personal liking (and to
            > avoid colliding mappings)? Then it would be easier to update the
            > scripts as new versions come without having to do all the
            > modifications each time.

            Large, complicated scripts with lots of options may want to use a
            separate file for defining mappings and other options. I proposed one
            mechanism for this. See the thread "customizing plugins" on vim-dev,
            started on 9/27/02. (On my todo list: produce an example of my
            proposed mechanism...)

            > 3. Perhaps one should think of making a Vim Scripting Style Guide?

            Johannes Zellner took a stab at that. I think the only style guide
            that carries any weight is

            :help write-plugin

            If you have suggestions for improving it, send a patch to Bram or open
            up a discussion on vim-dev. (Scripting is on the boundary between this
            list and vim-dev. It seems to me that guidelines for scripting cross
            the boundary to vim-dev.)

            > And a final plea to all you out there that makes scripts. Please put
            > more info/help into the script source. The problem is that many script
            > only have info/help on vim.sf.net. So that if you have downloaded a
            > script it is easy to find the same info as one find on the script page
            > of vim.sf.net. Especially how to install the script and a list of the
            > mappings, so that one can fast determine how to use the script.

            I support that. If the script is sufficiently complicated, it
            should be bundled with a separate help file. Even then, the header of
            the .vim file should contain pointers to the .txt file and to the URL
            for current versions.

            > Also put a bit more comments and "air" in the scripts so they are easier
            > to read. One do not need to do all in one line. :-)

            That's a question of personal programming style. A competing goal
            is to accomplish something in less than one screenful of script.

            HTH --Benji Fisher
          • Preben Randhol
            ... Thanks for the pointer, I ll look it up. ... I don t agree if this makes the script less readable. I know that for many scripts the goal is to write the
            Message 5 of 7 , Nov 4, 2002
            • 0 Attachment
              Benji Fisher <fisherbb@...> wrote on 04/11/2002 (10:23) :
              > Preben Randhol wrote:
              >
              > Large, complicated scripts with lots of options may want to use a
              > separate file for defining mappings and other options. I proposed one
              > mechanism for this. See the thread "customizing plugins" on vim-dev,
              > started on 9/27/02. (On my todo list: produce an example of my
              > proposed mechanism...)

              Thanks for the pointer, I'll look it up.

              > > Also put a bit more comments and "air" in the scripts so they are easier
              > > to read. One do not need to do all in one line. :-)
              >
              > That's a question of personal programming style. A competing goal
              > is to accomplish something in less than one screenful of script.

              I don't agree if this makes the script less readable. I know that for
              many scripts the "goal" is to write the whole thing in one line, but
              that does not make it readable for the rest of us. If the script is
              small then it can be ok if it fits one screen, but usually scripts are
              much longer than that. Therefore it makes it more readable if there is
              something like:

              [...]
              normal! $x
              endfunction

              " s:Add() will add abbreviations to ...
              "

              function s:Add()
              [...]

              instead of

              [...]
              normal! $x
              endfunction

              function s:Add()
              [...]


              --
              Preben Randhol ---------------- http://www.pvv.org/~randhol/ --
              Just vim it.
            • Steve Hall
              From: Preben Randhol ... Please don t forget the even more unreadable (IMO): [...] norm! $x endfu fu s:Add() [...] I wrote a script to
              Message 6 of 7 , Nov 4, 2002
              • 0 Attachment
                From: "Preben Randhol" <randhol+vim@...>
                >
                > Benji Fisher <fisherbb@...> wrote on 04/11/2002 (10:23) :
                > >
                > > Preben Randhol wrote:
                > >
                > > > Also put a bit more comments and "air" in the scripts so they
                > > > are easier to read. One do not need to do all in one line. :-)
                > >
                > > That's a question of personal programming style. A competing goal
                > > is to accomplish something in less than one screenful of script.
                >
                > I don't agree if this makes the script less readable. I know that for
                > many scripts the "goal" is to write the whole thing in one line, but
                > that does not make it readable for the rest of us. If the script is
                > small then it can be ok if it fits one screen, but usually scripts are
                > much longer than that. Therefore it makes it more readable if there is
                > something like:
                >
                > [...]
                > normal! $x
                > endfunction
                >
                > " s:Add() will add abbreviations to ...
                > "
                >
                > function s:Add()
                > [...]
                >
                > instead of
                >
                > [...]
                > normal! $x
                > endfunction
                >
                > function s:Add()
                > [...]

                Please don't forget the even more unreadable (IMO):

                [...]
                norm! $x
                endfu
                fu s:Add()
                [...]

                I wrote a script to convert a Vim script's short-form command and
                options to the long form if anybody would be interested in helping me
                finish it. Still has a few bugs, but it made only two errors on a 500+
                line file explorer script I recently downloaded.

                Steve Hall [ digitect@... ]
              • Preben Randhol
                ... Ah yes you are right! ... Sounds like a good script! I m used to Ada95 so I write function and endfunction without thinking of the short-forms :-) --
                Message 7 of 7 , Nov 4, 2002
                • 0 Attachment
                  Steve Hall <digitect@...> wrote on 04/11/2002 (14:10) :
                  >
                  > Please don't forget the even more unreadable (IMO):
                  >
                  > [...]
                  > norm! $x
                  > endfu
                  > fu s:Add()
                  > [...]

                  Ah yes you are right!

                  > I wrote a script to convert a Vim script's short-form command and
                  > options to the long form if anybody would be interested in helping me
                  > finish it. Still has a few bugs, but it made only two errors on a 500+
                  > line file explorer script I recently downloaded.

                  Sounds like a good script!

                  I'm used to Ada95 so I write function and endfunction without thinking
                  of the short-forms :-)

                  --
                  Preben Randhol ---------------- http://www.pvv.org/~randhol/ --
                  Just vim it.
                Your message has been successfully submitted and would be delivered to recipients shortly.