On 2011-07-14, sinbad wrote:
> hi,
>
> i have a mapping for "]", i want this mapping to be available
> in all other modes except diff mode, since ]c is used to go to
> next diff, how can i do that.
If you do that, you'll lose the use of a lot of commands that begin
with ']'. See
:help ]
Also, your ] command won't be executed until about one second after
it's typed. See
:help 'timeoutlen'
:help 'ttimeout'
Consequently, it might be more useful for you to map ]] instead of
].
That said, there are a number of ways you can make that mapping
unavailable in diff mode.
It can be tricky to do anything only in diff mode since Vim has so
many ways to enter that mode. If the only time you use diff mode is
when you run vimdiff, then the solution is pretty simple: just
condition your mapping on &diff in your .vimrc or _vimrc, e.g.,
if !&diff
map ] whatever
endif
If you enter diff mode in other ways and you're running on Windows
the solution is also pretty simple: map ] in your _vimrc and unmap
it in the MyDiff() function that's usually included in _vimrc.
function MyDiff()
silent! unmap ]
...
endfunction
The "silent!" avoid the error message if ] is not mapped.
That last solution is a bit more complicated if you're running on
Unix because there is normally no need for a MyDiff() function on
Unix and none is provided. However, one is given in the reference
manual. Go to ":help diff-diffexpr" and scroll down about 40 lines
to the example.
One problem with unmapping that key automatically when you enter
diff mode is that there is no automatic way that I know of to re-map
it when you leave diff mode. One way around that is to create a
command that turns diff mode off and at the same time executes your
mapping. For example:
command! Diffoff diffoff <bar> map ] whatever
That's untested, but I think it will work.
HTH,
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