Tuesday, November 1, 2011

Re: &diff and filetype

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

No comments:

Post a Comment