[prev in list] [next in list] [prev in thread] [next in thread] 

List:       vim
Subject:    Re: mapping <Insert> to gR
From:       Benji Fisher <benji () member ! AMS ! org>
Date:       2002-12-11 15:57:38
[Download RAW message or body]

Steve Hall wrote:
> 
> By default, it appears that <Insert> effectively toggles normal r and
> normal i (on win32, others?). However, I'd like to map it to toggle
> between normal *gR* and normal i except that I think I've uncovered a
> bug that prevents it.
> 
>     imap <Insert> <C-o>gR
> 
> works for me (which is only the first half of the toggle), but
> 
>     imap <silent> <Insert> <C-o>:call Replacemode()<CR>
>     function! Replacemode()
[snip]
>             " start replace mode
>             normal gR
>         else
>             " end replace mode
>             normal i
>         endif
>     endfunction
> 
> does not. Even after removing the whole upper initialization part I am
> unable to get to virtual-replace mode. Can anybody spot the error?
> 
> Thanks once again.
> 
> Steve Hall  [ digitect(at)mindspring.com ]

      Neither of your :normal lines gives a "complete command" in the 
sense of

:help :normal

I would try something like this:

:inoremap <silent> <Insert> <C-R>=ToggleMode()<CR>

where the ToggleMode() function returns either "x\<Esc>gR\<Del>" or 
"\<Esc>a".  Adding and then deleting the "x" solves the problem of not 
moving the cursor when going from Insert to VReplace mode; I am not sure 
what to do when going from VReplace to Insert mode.  (Special cases: 
start of line, end of line, empty line, middle of line.)  Maybe using 
<C-O> instead of <Esc> will work...

HTH					--Benji Fisher

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic