Re: mapping g

2006-11-16 Thread Bram Moolenaar

Manfred Georg wrote:

> 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.

Right.  Thanks for the fix.

-- 
Emacs is a nice OS - but it lacks a good text editor.
That's why I am using Vim.  --Anonymous

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///


Re: mapping g

2006-11-16 Thread Manfred Georg


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.vim2006-05-08 
10:42:46.0 -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


Re: mapping g

2006-11-15 Thread Benji Fisher
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.vim2006-05-08 
10:42:46.0 -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


Re: mapping g

2006-11-15 Thread A.J.Mechelynck

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.

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


Method I (secommended)

Map something which will not collide with Vim's own mappings, such as F7 
(which is still reachable by extending the fingers straight up from the home 
position).


Method II
-
There are still settings which should be set before everything happens (such 
as 'nocompatible' or ":language") and that's reason enough to keep the vimrc 
before all the rest. But you can still create a script to be sourced after all 
plugins: write an after-plugin (see ":help after-directory) and name your 
script, for instance (on Unix/Linux) ~/.vim/after/plugin/last.vim or (in 
Vim notation on Windows) ~/vimfiles/after/plugin/last.vim (the name 
starting with  is intended to have it sourced even after your own other 
after-plugins if any). Place into this file any commands that must 
imperatively be run after all plugins.


Method III
--
If Method II doesn't source your custom script late enough, place it in some 
other directory, for example (depending on platform) ~/.vim/macros/ or 
~/vimfiles/macros/ and source it from an autocommand for the VimEnter event, i.e.,


:autocmd VimEnter * runtime macros/last.vim

This autocommand would be defined (one line) in your vimrc.


Best regards,
Tony.


mapping g

2006-11-15 Thread Manfred Georg

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.

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

##
"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