mapping {

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

mapping {

gmguyx

Since I type curly braces "{}" more often than brackets "[]", I would
like to swap the 2 keys so that so that typing "[" gives me "{" and
typing "<S-[>" gives me "["

So I do:

inoremap [ {
inoremap ] }
inoremap <S-{> [
inoremap <S-}> ]

However, this does not work because now I always get a curly brace
regardless of whether I press the <Shift> key or not.

Is there a way to do this?


--~--~---------~--~----~------------~-------~--~----~
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: mapping {

Bill McCarthy

On Mon 23-Jul-07 10:19pm -0600, gmguyx wrote:

> Since I type curly braces "{}" more often than brackets "[]", I would
> like to swap the 2 keys so that so that typing "[" gives me "{" and
> typing "<S-[>" gives me "["
>
> So I do:
>
> inoremap [ {
> inoremap ] }
> inoremap <S-{> [
> inoremap <S-}> ]
>
> However, this does not work because now I always get a curly brace
> regardless of whether I press the <Shift> key or not.
>
> Is there a way to do this?

 inoremap [ {
 inoremap ] }
 inoremap { [
 inoremap } ]

--
Best regards,
Bill


--~--~---------~--~----~------------~-------~--~----~
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: mapping {

Tony Mechelynck
In reply to this post by gmguyx

gmguyx wrote:

> Since I type curly braces "{}" more often than brackets "[]", I would
> like to swap the 2 keys so that so that typing "[" gives me "{" and
> typing "<S-[>" gives me "["
>
> So I do:
>
> inoremap [ {
> inoremap ] }
> inoremap <S-{> [
> inoremap <S-}> ]
>
> However, this does not work because now I always get a curly brace
> regardless of whether I press the <Shift> key or not.
>
> Is there a way to do this?

What do you get (in Insert mode with no mappings) when you hit shift-[ or
shift-] ? (I get deadkey-ball-above and deadkey-macron). That is what you
should youse as the {lhs} of your last two mappings.
  For instance, is shift-[ is { then you should use

        inoremap   {   [


Best regards,
Tony.
--
I've found my niche.  If you're wondering why I'm not there, there was
this little hole in the bottom ...
                -- John Croll

--~--~---------~--~----~------------~-------~--~----~
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: mapping {

gmguyx

Thanks for the quick replies Bill and Tony. I can't believe I didn't
think of that! I think it's because I was worried about recursive
mappings but I forgot that "noremap" takes care of that problem.
Thanks again.


--~--~---------~--~----~------------~-------~--~----~
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: mapping {

John Little-4
gmguyx wants to swap bracket keys...

Using just inoremap this way can be frustrating, because it doesn't affect searches; for that you need to use noremap! or add cnoremap, and mucking about with characters that are used by Vim's own syntax starts breaking scripts in obscure ways, when the scripts use :eval maybe.  Also, normal mode r, f and t still use the old meaning.

However, one can use the language map stuff (see :help language-mapping):
    set iminsert=1 imsearch=1
    lnoremap [ {
    lnoremap { [
    lnoremap ] }
    lnoremap } ]

Command mode starts with the lang map off, so switch it on always with
    noremap : :<c-^>

It really can be simpler to do it at a lower level, using xmodmap with X or mapping scan codes in Windows.

HTH, John

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