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

Mapping only in specific buffer

Expand Messages
  • Ni Va
    Hi, I would like to map ]c diff jump only in a vim buffer. I have done this for the moment but would like to make conditional test on &diff var : map
    Message 1 of 6 , Jun 12, 2014
    • 0 Attachment
      Hi,


      I would like to map ]c diff jump only in a vim buffer.

      I have done this for the moment but would like to make conditional test on &diff var :
      map <F2> : norm ]c<CR>


      Thank you

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Ni Va
      In fact I would like to get two specific meaning on the same F2 key as I am reading a diff buffer or a normal buffer. Thank you very much ... -- -- You
      Message 2 of 6 , Jun 12, 2014
      • 0 Attachment
        In fact I would like to get two specific meaning on the same F2 key as I am reading a diff buffer or a normal buffer.

        Thank you very much

        On Thursday, June 12, 2014 5:55:53 PM UTC+2, Ni Va wrote:
        > Hi,
        >
        >
        > I would like to map ]c diff jump only in a vim buffer.
        >
        > I have done this for the moment but would like to make conditional test on &diff var :
        > map <F2> : norm ]c<CR>
        >
        >
        > Thank you

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • Gary Johnson
        ... If you re mapping a key to be pressed in normal mode, you don t need to go into ex mode and use :normal--just map the command directly. map ]c To make
        Message 3 of 6 , Jun 12, 2014
        • 0 Attachment
          On 2014-06-12, Ni Va wrote:
          > Hi,
          >
          >
          > I would like to map ]c diff jump only in a vim buffer.
          >
          > I have done this for the moment but would like to make conditional
          > test on &diff var :
          > map <F2> : norm ]c<CR>

          If you're mapping a key to be pressed in normal mode, you don't need
          to go into ex mode and use :normal--just map the command directly.

          map <F2> ]c

          To make a mapping apply only in a particular buffer, use the
          <buffer> modifier.

          map <buffer> <F2> ]c

          See

          :help :map-<buffer>

          That :map command has to be executed in the buffer in which you want
          it to apply. If you want it to apply to buffers of a certain file
          type, you can put the command in a file in your
          ~/.vim/after/ftplugin directory. See

          :help ftplugin-overrule

          Or, you can put a FileType autocommand in your ~/.vimrc like this
          example that assumes you want the mapping to be defined only for the
          c file type.

          au FileType c map <buffer> <F2> ]c

          You can make mapping conditional on option settings such as 'diff',
          but how you do that depends on the behavior you're really trying to
          achieve and when you want the mapping to depend on 'diff': when the
          mapping is defined or when <F2> is pressed.

          Regards,
          Gary

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • Павлов Николай Алекса
          ... Hash: SHA512 Why are you using :norm here? Your mapping is incorrect: 1. You do not need :norm. Just using ]c should be enough in this circumstances. 2.
          Message 4 of 6 , Jun 12, 2014
          • 0 Attachment
            -----BEGIN PGP SIGNED MESSAGE-----
            Hash: SHA512

            Why are you using :norm here? Your mapping is incorrect:

            1. You do not need :norm. Just using "]c" should be enough in this circumstances.
            2. You do not need :map without n. Your mapping is not going to work in visual mode (as long as you use :normal).
            3. You should not be using :map without nore and :normal without bang unless you have to.

            What I would write is

            noremap <expr> <F2> &diff ? ']c' : 'something else'

            (note: just ']c' works in all modes noremap maps in, so I do not follow 2.).

            On June 12, 2014 7:55:53 PM GMT+03:00, Ni Va <nivaemail@...> wrote:
            >Hi,
            >
            >
            >I would like to map ]c diff jump only in a vim buffer.
            >
            >I have done this for the moment but would like to make conditional test
            >on &diff var :
            >map <F2> : norm ]c<CR>
            >
            >
            >Thank you
            -----BEGIN PGP SIGNATURE-----
            Version: APG v1.1.1

            iQI1BAEBCgAfBQJTmdYTGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
            HhHSvqvWD/9AT+bcuChsthWqliMk2zFcwCNuKrdKYTuWwU8zaXRfl0+b6QIC/bSH
            33AL9pzSEwKd8QSBS1l2FhO9edFY4p3YCMaXFrA3f9nR1CVvrsgP+HhSkmjRjIPo
            vlI4MKNRqbeaoZ/sSqcOI7QzeOmARiAvk0gJvbDbFprPN2ywXxsb9tjBbn4unApD
            dP2m5ys677Z+BrRCPKlbWrxAJD6RyMXtn0xbbbyRXyX+NHjXfH2Ja0y8KPBJRng7
            f1pPQJZPP6m7PiYRBq0KVhFhcK2c3kil40br0ZSZMm+4k9FnIrk2mShl/QHeGQFZ
            XZXHOnvQN12/D+YXvbX6WBlnxyXXemTzeuTPyLY2EBflDhEn6+NLL8EIyjj0Iec7
            3/S6UKJ9jA3ohYbkWP7CWdWlGDlCdPleyt1u39cyh1Ly7SCgW5mt/Y0Drs8TIxnT
            IbHwvjwa2rB7Z/sola9qljciabHqkkPGVlXRimkEXRlhJFsJ8UT2hTJmmN3MxLjc
            Ib+ybbewwjGGRzSirHIfEmmWv2bBrtN5WQykCr2vYjlXYe3GAH306S4cHYNo1wSv
            cDUicIpIYQ4HV/rZIkoshF+wq3xF9HO8bnvARwnWRgH0God28bhTObk82GpMp2Yf
            jd02nV1THWgTwnoLz6ZkbRuvVGHzpMxx2+hx/smFfENyY1oRuEuwqA==
            =WEaa
            -----END PGP SIGNATURE-----

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          • Gary Johnson
            ... In that case, this in your ~/.vimrc might do what you want. nnoremap &diff ? ]c : :echo hello where I just made up :echo hello
            Message 5 of 6 , Jun 12, 2014
            • 0 Attachment
              On 2014-06-12, Ni Va wrote:

              > On Thursday, June 12, 2014 5:55:53 PM UTC+2, Ni Va wrote:

              > > I would like to map ]c diff jump only in a vim buffer.
              > >
              > > I have done this for the moment but would like to make
              > > conditional test on &diff var :
              > > map <F2> : norm ]c<CR>

              > In fact I would like to get two specific meaning on the same F2
              > key as I am reading a diff buffer or a normal buffer.

              In that case, this in your ~/.vimrc might do what you want.

              nnoremap <expr> <F2> &diff ? "]c" : ":echo 'hello'<CR>"

              where I just made up ":echo 'hello'" because you didn't say what the
              mapping was to be in the normal buffer.

              :help :map-<expr>

              Because you want this mapping to be defined in all buffers, you
              don't need or want the <buffer> modifier I mentioned previously.

              Please don't top-post to this list.

              Regards,
              Gary

              --
              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/d/optout.
            • Ni Va
              Hi Gary, In fact I have in mind the mapping known on Windows OS used to search forward or backward in registry or in visual studio environnment. I would
              Message 6 of 6 , Jun 12, 2014
              • 0 Attachment
                Hi Gary,

                In fact I have in mind the mapping <F3> known on Windows OS used to search forward or backward in registry or in visual studio environnment.

                I would like to used only this keystroke to search previous or next occurence:
                1/ in a diff buffer : a difference
                2/ in a normal buffer : the last searched pattern
                3/ .... etC...


                On Thursday, June 12, 2014 6:27:31 PM UTC+2, Gary Johnson wrote:
                > On 2014-06-12, Ni Va wrote:
                >
                > > Hi,
                >
                > >
                >
                > >
                >
                > > I would like to map ]c diff jump only in a vim buffer.
                >
                > >
                >
                > > I have done this for the moment but would like to make conditional
                >
                > > test on &diff var :
                >
                > > map <F2> : norm ]c<CR>
                >
                >
                >
                > If you're mapping a key to be pressed in normal mode, you don't need
                >
                > to go into ex mode and use :normal--just map the command directly.
                >
                >
                >
                > map <F2> ]c
                >
                >
                >
                > To make a mapping apply only in a particular buffer, use the
                >
                > <buffer> modifier.
                >
                >
                >
                > map <buffer> <F2> ]c
                >
                >
                >
                > See
                >
                >
                >
                > :help :map-<buffer>
                >
                >
                >
                > That :map command has to be executed in the buffer in which you want
                >
                > it to apply. If you want it to apply to buffers of a certain file
                >
                > type, you can put the command in a file in your
                >
                > ~/.vim/after/ftplugin directory. See
                >
                >
                >
                > :help ftplugin-overrule
                >
                >
                >
                > Or, you can put a FileType autocommand in your ~/.vimrc like this
                >
                > example that assumes you want the mapping to be defined only for the
                >
                > c file type.
                >
                >
                >
                > au FileType c map <buffer> <F2> ]c
                >
                >
                >
                > You can make mapping conditional on option settings such as 'diff',
                >
                > but how you do that depends on the behavior you're really trying to
                >
                > achieve and when you want the mapping to depend on 'diff': when the
                >
                > mapping is defined or when <F2> is pressed.
                >
                >
                >
                > Regards,
                >
                > Gary

                --
                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/d/optout.
              Your message has been successfully submitted and would be delivered to recipients shortly.