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

&diff and filetype

Expand Messages
  • Joachim Hofmann
    Hello, I want to set a mapping, only when a certain (Ruby-)-Filetype event appears. I got a script where the mapping is defined, the mapping is created, and it
    Message 1 of 8 , Nov 1, 2011
    • 0 Attachment
      Hello,

      I want to set a mapping, only when a certain (Ruby-)-Filetype event appears.
      I got a script where the mapping is defined, the mapping is created, and
      it works.
      But I don't want this mapping to be defined when vim is in diff-mode.
      In my versioning system I start vim for viewing diffs with
      gview -d "%1" "%2"

      Problem: It seems that when the filetype is set, the diff mode is not
      set yet
      so asking in my filetype fired script:
      if &diff
      map x y
      ...
      does not solve the task, because &diff is 0 and is set to 1 later.

      How/where can I solve this condition-dependent mapping?

      Thank You

      Joachim

      --
      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
    • Andy Wokula
      ... -- Andy -- 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
      Message 2 of 8 , Nov 1, 2011
      • 0 Attachment
        Am 01.11.2011 17:17, schrieb Joachim Hofmann:
        > Hello,
        >
        > I want to set a mapping, only when a certain (Ruby-)-Filetype event appears.
        > I got a script where the mapping is defined, the mapping is created, and it works.
        > But I don't want this mapping to be defined when vim is in diff-mode.
        > In my versioning system I start vim for viewing diffs with
        > gview -d "%1" "%2"
        >
        > Problem: It seems that when the filetype is set, the diff mode is not set yet
        > so asking in my filetype fired script:
        > if &diff
        > map x y
        > ...
        > does not solve the task, because &diff is 0 and is set to 1 later.
        >
        > How/where can I solve this condition-dependent mapping?
        >
        > Thank You
        >
        > Joachim

        Example orig mapping:
        :nmap <buffer> X <Plug>DoY

        Same mapping prepared for diff-mode:
        :nmap <buffer><expr> X !&diff ? "<Plug>DoY" : ""

        :h :map-<expr>

        --
        Andy

        --
        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
      • Gary Johnson
        ... You can use the FilterWritePre or FilterWritePost autocommand event to trigger an unmapping, e.g. something like this: au FilterWritePre * if &diff && &ft
        Message 3 of 8 , Nov 1, 2011
        • 0 Attachment
          On 2011-11-01, Joachim Hofmann wrote:
          > Hello,
          >
          > I want to set a mapping, only when a certain (Ruby-)-Filetype event appears.
          > I got a script where the mapping is defined, the mapping is created,
          > and it works.
          > But I don't want this mapping to be defined when vim is in diff-mode.
          > In my versioning system I start vim for viewing diffs with
          > gview -d "%1" "%2"
          >
          > Problem: It seems that when the filetype is set, the diff mode is
          > not set yet
          > so asking in my filetype fired script:
          > if &diff
          > map x y
          > ...
          > does not solve the task, because &diff is 0 and is set to 1 later.
          >
          > How/where can I solve this condition-dependent mapping?

          You can use the FilterWritePre or FilterWritePost autocommand event
          to trigger an unmapping, e.g. something like this:

          au FilterWritePre * if &diff && &ft == "ruby" | silent! unmap x | endif

          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
        • Christian Brabandt
          ... Yes, filetype autocommands trigger earlier than the diff setting. I would use a FilterWritePost autocommand to delete the mapping, something like: au
          Message 4 of 8 , Nov 1, 2011
          • 0 Attachment
            On Tue, November 1, 2011 5:17 pm, Joachim Hofmann wrote:
            > Hello,
            >
            > I want to set a mapping, only when a certain (Ruby-)-Filetype event
            > appears.
            > I got a script where the mapping is defined, the mapping is created, and
            > it works.
            > But I don't want this mapping to be defined when vim is in diff-mode.
            > In my versioning system I start vim for viewing diffs with
            > gview -d "%1" "%2"
            >
            > Problem: It seems that when the filetype is set, the diff mode is not
            > set yet
            > so asking in my filetype fired script:
            > if &diff
            > map x y
            > ...
            > does not solve the task, because &diff is 0 and is set to 1 later.
            >
            > How/where can I solve this condition-dependent mapping?

            Yes, filetype autocommands trigger earlier than the diff setting.
            I would use a FilterWritePost autocommand to delete the mapping,
            something like:
            au FilterWritePost * if &diff && mapcheck('<Leader>xy', 'n') | sil unmap
            <buffer> <Leader>xy | endif

            That should work[输, but see the documentation for mapcheck and unmap
            to know which unmap command to use for which mode. This depends on
            your mapping obviously.

            regards,
            Christian

            --
            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
          • Ben Fritz
            ... How about using diffexpr instead of a FilterWritePost autocmd? That should also work I think and is a little more specific. If you already have a
            Message 5 of 8 , Nov 1, 2011
            • 0 Attachment
              On Nov 1, 11:53 am, "Christian Brabandt" <cbli...@...> wrote:
              > On Tue, November 1, 2011 5:17 pm, Joachim Hofmann wrote:
              > > Hello,
              >
              > > I want to set a mapping, only when a certain (Ruby-)-Filetype event
              > > appears.
              > > I got a script where the mapping is defined, the mapping is created, and
              > > it works.
              > > But I don't want this mapping to be defined when vim is in diff-mode.
              > > In my versioning system I start vim for viewing diffs with
              > > gview -d "%1"  "%2"
              >
              > > Problem: It seems that when the filetype is set, the diff mode is not
              > > set yet
              > > so asking in my filetype fired script:
              > >      if &diff
              > >        map x y
              > >      ...
              > > does not solve the task, because &diff is 0 and is set to 1 later.
              >
              > > How/where can I solve this condition-dependent mapping?
              >
              > Yes, filetype autocommands trigger earlier than the diff setting.
              > I would use a FilterWritePost autocommand to delete the mapping,
              > something like:
              > au FilterWritePost * if &diff && mapcheck('<Leader>xy', 'n') | sil unmap
              > <buffer> <Leader>xy | endif
              >
              > That should work[ ], but see the documentation for mapcheck and unmap
              > to know which unmap command to use for which mode. This depends on
              > your mapping obviously.
              >

              How about using 'diffexpr' instead of a FilterWritePost autocmd? That
              should also work I think and is a little more specific. If you already
              have a diffexpr it would be easy to add the unmap functionality,
              otherwise the autocmd may be easier.

              --
              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
            • Joachim Hofmann
              Hmmm, seems that the FilterWritePre event does not appear. in my .vimrc: autocmd FilterWritePre * if &diff | colorscheme darkblue | endif does nothing. Any
              Message 6 of 8 , Nov 2, 2011
              • 0 Attachment
                Hmmm, seems that the FilterWritePre event does not appear.

                in my .vimrc:
                autocmd FilterWritePre * if &diff | colorscheme darkblue | endif

                does nothing.

                Any Ideas?

                Joachim

                --
                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
              • Christian Brabandt
                ... Check with ... Use one of the other suggestions. regards, Christian -- You received this message from the vim_use maillist. Do not top-post! Type your
                Message 7 of 8 , Nov 2, 2011
                • 0 Attachment
                  On Wed, November 2, 2011 12:06 pm, Joachim Hofmann wrote:
                  > Hmmm, seems that the FilterWritePre event does not appear.
                  >
                  > in my .vimrc:
                  > autocmd FilterWritePre * if &diff | colorscheme darkblue | endif
                  >
                  > does nothing.

                  Check with
                  :h 'verbose'

                  >
                  > Any Ideas?

                  Use one of the other suggestions.

                  regards,
                  Christian



                  --
                  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
                • Joachim Hofmann
                  This works in my .vimrc , it overwrites a previous filetype fired mapping. map &diff ? [c : Thank You -- You received this message
                  Message 8 of 8 , Nov 3, 2011
                  • 0 Attachment
                    This works in my .vimrc , it overwrites a previous filetype fired mapping.

                    map <buffer><expr> <F1> &diff ? "[c" : ""

                    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
                  Your message has been successfully submitted and would be delivered to recipients shortly.