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

Re: &diff and filetype

Expand Messages
  • 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 1 of 8 , Nov 1, 2011
      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 2 of 8 , Nov 1, 2011
        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 3 of 8 , Nov 2, 2011
          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 4 of 8 , Nov 2, 2011
            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 5 of 8 , Nov 3, 2011
              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.