how to disable mappings within mappings

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

how to disable mappings within mappings

gmguyx

I have swapped the ":" and ";" keys:

nnoremap : ;
nnoremap ; :

I would like it to behave this way only when I'm actually typing it,
but I don't want it to behave this way when I create other maps. For
example if I want to do the following map:

map <C-Down> :bp<CR>

it won't work. I have to instead replace the ":" with a ";" because of
the previous mappings I did for ":" and ";". ie, I have to do:

map <C-Down> ;bp<CR>

to make it work. I also have this problem when I'm writing vim
functions. Is there any way to make mappings only apply when you are
typing and not when you are creating other maps?


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: how to disable mappings within mappings

Larson, David

> I have swapped the ":" and ";" keys:
>
> nnoremap : ;
> nnoremap ; :
>
> I would like it to behave this way only when I'm actually typing it,
> but I don't want it to behave this way when I create other maps. For
> example if I want to do the following map:
>
> map <C-Down> :bp<CR>
>
> it won't work. I have to instead replace the ":" with a ";" because of
> the previous mappings I did for ":" and ";". ie, I have to do:
>
> map <C-Down> ;bp<CR>

Would this work?
noremap <C-Down> :bp<cr>

> to make it work. I also have this problem when I'm writing vim
> functions.

Remapping : to ; might be a bad idea then.

> Is there any way to make mappings only apply when you are
> typing and not when you are creating other maps?

noremap should do the job for you.


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to disable mappings within mappings

Tony Mechelynck
In reply to this post by gmguyx

gmguyx wrote:

> I have swapped the ":" and ";" keys:
>
> nnoremap : ;
> nnoremap ; :
>
> I would like it to behave this way only when I'm actually typing it,
> but I don't want it to behave this way when I create other maps. For
> example if I want to do the following map:
>
> map <C-Down> :bp<CR>
>
> it won't work. I have to instead replace the ":" with a ";" because of
> the previous mappings I did for ":" and ";". ie, I have to do:
>
> map <C-Down> ;bp<CR>
>
> to make it work. I also have this problem when I'm writing vim
> functions. Is there any way to make mappings only apply when you are
> typing and not when you are creating other maps?

The {rhs} of a mapping will be re-examined for further mappings except if the
_defining_ mapping uses "noremap". So just define

        :noremap <C-Down> :bp<CR>

where both colons are of course obtained by hitting ; but display as colons.


See ":help :noremap" which applies to:

        :noremap
        :nnoremap
        :vnoremap
        :xnoremap
        :snoremap
        :onoremap
        :noremap!
        :inoremap
        :lnoremap
        :cnoremap


Best regards,
Tony.
--
When Marriage is Outlawed,
Only Outlaws will have Inlaws.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to disable mappings within mappings

Gary Johnson
In reply to this post by gmguyx

On 2007-08-07, gmguyx <[hidden email]> wrote:

> I have swapped the ":" and ";" keys:
>
> nnoremap : ;
> nnoremap ; :
>
> I would like it to behave this way only when I'm actually typing it,
> but I don't want it to behave this way when I create other maps. For
> example if I want to do the following map:
>
> map <C-Down> :bp<CR>

   noremap <C-Down> :bp<CR>

> it won't work. I have to instead replace the ":" with a ";" because of
> the previous mappings I did for ":" and ";". ie, I have to do:
>
> map <C-Down> ;bp<CR>
>
> to make it work. I also have this problem when I'm writing vim
> functions.

Use ":normal!", with the exclamation point, when invoking
normal-mode commands from a function.

> Is there any way to make mappings only apply when you are
> typing and not when you are creating other maps?

Not that I know of.  The only way I know of is to insure that they
_don't_ apply when creating other maps and invoking normal-mode
commands within functions.

HTH,
Gary

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to disable mappings within mappings

gmguyx
In reply to this post by Tony Mechelynck

Sorry for the unnecessary distraction - I realized soon after I sent
this out that I forgot the noremap for <C-Down>.

However, the problem still remains for functions which do expand the
mappings. Frequently when I create new mappings, I find that some of
my functions will break and I'll have to go back and change all the
chars in those functions to reflect the new mappings.


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to disable mappings within mappings

Tony Mechelynck

gmguyx wrote:
> Sorry for the unnecessary distraction - I realized soon after I sent
> this out that I forgot the noremap for <C-Down>.
>
> However, the problem still remains for functions which do expand the
> mappings. Frequently when I create new mappings, I find that some of
> my functions will break and I'll have to go back and change all the
> chars in those functions to reflect the new mappings.

Use noremap there too ?


Best regards,
Tony.
--
"I have made mistakes but I have never made the mistake of claiming
that I have never made one."
                -- James Gordon Bennett

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to disable mappings within mappings

gmguyx

On Aug 7, 1:50 pm, Tony Mechelynck <[hidden email]>
wrote:
> > However, the problem still remains for functions which do expand the
> > mappings. Frequently when I create new mappings, I find that some of
> > my functions will break and I'll have to go back and change all the
> > chars in those functions to reflect the new mappings.
>
> Use noremap there too ?

How do you use noremap inside a function? Here is what I've done:

-------------------------------
inoremap 9 (
inoremap 0 )
inoremap ( 9
inoremap ) 0

inoremap <A-e> <Esc>:call InsertIf()<CR>i
function InsertIf()
        execute 'normal iif ()'
endfunction
-------------------------------

Even though I specify inoremap in the mapping, the function which the
mapping calls still maps the "()" to "90".


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to disable mappings within mappings

gmguyx

On Aug 7, 1:36 pm, Gary Johnson <[hidden email]> wrote:
> > to make it work. I also have this problem when I'm writing vim
> > functions.
>
> Use ":normal!", with the exclamation point, when invoking
> normal-mode commands from a function.

Thanks Gary!


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to disable mappings within mappings

gmguyx
In reply to this post by gmguyx

Please disregard this post as I see that Gary already answered this
question. Sorry for all the distractions.

On Aug 7, 2:32 pm, gmguyx <[hidden email]> wrote:

> On Aug 7, 1:50 pm, Tony Mechelynck <[hidden email]>
> wrote:
>
> > > However, the problem still remains for functions which do expand the
> > > mappings. Frequently when I create new mappings, I find that some of
> > > my functions will break and I'll have to go back and change all the
> > > chars in those functions to reflect the new mappings.
>
> > Use noremap there too ?
>
> How do you use noremap inside a function? Here is what I've done:
>
> -------------------------------
> inoremap 9 (
> inoremap 0 )
> inoremap ( 9
> inoremap ) 0
>
> inoremap <A-e> <Esc>:call InsertIf()<CR>i
> function InsertIf()
>         execute 'normal iif ()'
> endfunction
> -------------------------------
>
> Even though I specify inoremap in the mapping, the function which the
> mapping calls still maps the "()" to "90".


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: how to disable mappings within mappings

Yegappan Lakshmanan
In reply to this post by gmguyx

Hi,

On 8/7/07, gmguyx <[hidden email]> wrote:

>
> I have swapped the ":" and ";" keys:
>
> nnoremap : ;
> nnoremap ; :
>
> I would like it to behave this way only when I'm actually typing it,
> but I don't want it to behave this way when I create other maps. For
> example if I want to do the following map:
>
> map <C-Down> :bp<CR>
>
> it won't work. I have to instead replace the ":" with a ";" because of
> the previous mappings I did for ":" and ";". ie, I have to do:
>
> map <C-Down> ;bp<CR>
>
> to make it work. I also have this problem when I'm writing vim
> functions. Is there any way to make mappings only apply when you are
> typing and not when you are creating other maps?
>

In addition to the replies you have received so far, you can refer
to following tutorial on mapping keys in Vim:

http://www.geocities.com/yegappan/vim_keymap.html

- Yegappan

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---