Thanks,  sorry about the wrong file name, (computer went down and I
couldn't check it).  Thanks for the patch.  I guess, the vimrc/plugin
thing makes sense...it still ends up looking like an ugly hack though.
I guess a question, is how often does this bite people?  Does it
make sense to have some standard mechanism to deal with this?  Perhaps
in the example vimrc files, have an example source after plugins file?
Anyway, no big deal.  Thanks for a great editor.

Manfred

On Wed, 15 Nov 2006, Benji Fisher wrote:

On Wed, Nov 15, 2006 at 08:11:42PM -0600, Manfred Georg wrote:
Hi,

Apparently this isn't a very popular thing to do, but I remap g
to help me do indentation.  There are two problems with this.
In gvimrc_example.vim , there is some code (which has been copied
all sorts of places) which does automatic
jump to last position when file was closed.  This uses the command g'"
Unfortunately when g has been remapped it triggers this mapping.

To fix this the line with
\| exe "normal g'\"" | endif
should read
\| exe "normal! g'\"" | endif

the ! stops it from remapping g to the local mapping.

    The patch at the end of this e-mail implements this change.  The
file is vimrc_example.vim, not gvimrc_example.vim .  (You can probably
do this yourself.  See my tip at
http://www.vim.org/tips/tip.php?tip_id=618 .)

Also, some plugins create some mappings that start with g .
The problem is that I don't want to wait for the disambiguation delay
before triggering my mapping.  So I want to unmap those mappings in
the user .vimrc .  The problem is that plugins are sourced after
the user .vimrc .  This makes it impossible to countermand the
mappings created by the plugins automatically (barring using even more
magical techniques like autocmd).  It really seems to me like the
.vimrc should be sourced after the plugins, it should have the final say.

Thank you,

Manfred

    The following function could use some more testing, but the idea is
that

:call Mapclear('g')

should :unmap any mapping that starts with "g".  If you do this in your
after/plugin/ directory (maybe after/plugin/zzz.vim ) and then define
your mapping for "g", then you should be in good shape.

fun! Mapclear(init)
 redir => mapstr
 execute "silent! map" a:init
 redir END
 let maplist = split(mapstr, '\n')
 if len(maplist) == 1 && maplist[0] == 'No mapping found'
   return
 endif
 for mapline in maplist
   let parts = split(mapline)
   let mode = mapline[0]
   let lhs = parts[mode == ' ' ? 0 : 1]
   echo mode . "unmap" lhs
 endfor
endfun

    There is a chicken-and-egg problem:  you want to be able to
enable/disable plugins in your vimrc file, so it has to be read before
the plugins are loaded.  There are other surprises, too:  you might
expect command-line options to override vimrc settings, but they do not.
(Maybe they do not *always* override vimrc settings.)  I think we are
stuck with the current system for reasons of backwards compatibility.
It may even be a question of vi-compatibility.

:help design-compatible

HTH                                     --Benji Fisher

*** /usr/local/share/vim/vim70/vimrc_example.vim        2006-05-08 
10:42:46.000000000 -0400
--- temp/vimrc_example.vim      2006-11-15 23:30:24.792231281 -0500
***************
*** 69,75 ****
   " (happens when dropping a file on gvim).
   autocmd BufReadPost *
     \ if line("'\"") > 0 && line("'\"") <= line("$") |
!     \   exe "normal g`\"" |
     \ endif

   augroup END
--- 69,75 ----
   " (happens when dropping a file on gvim).
   autocmd BufReadPost *
     \ if line("'\"") > 0 && line("'\"") <= line("$") |
!     \   exe "normal! g`\"" |
     \ endif

   augroup END


##################################################################
"Must I do all the evil I can before I learn to shun it?  Is it
not enough to know the evil to shun it?  If not, we should be
sincere enough to admit that we love evil too well to give it up."
                                 - Mohandas K. Gandhi

Reply via email to