Mapping alt+arrow keys?

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

Mapping alt+arrow keys?

Shaun Friedle
Hi,

I'm having difficultly mapping alt + the arrow keys at startup in MacVim.

So, I have this in my .vimrc in order to move between windows:

map <M-Up> :wincmd k<CR>
map <M-Down> :wincmd j<CR>
map <M-Left> :wincmd h<CR>
map <M-Right> :wincmd l<CR>

But this doesn't work in MacVim at startup, alt+left/right navigate to previous/next word and alt+up/down seem to navigate to previous/next paragraph. It does work if I do:

:source ~/.vimrc

So somehow if my execute my vimrc after MacVim has started then the mapping works correctly. Everything else in my vimrc works normally without having to manually source it including other key mappings. I've also tried deleting everything else in my vimrc except those 4 lines and it still doesn't work. If I change the maps to:

map <C-M-Up> :wincmd k<CR>
map <C-M-Down> :wincmd j<CR>
map <C-M-Left> :wincmd h<CR>
map <C-M-Right> :wincmd l<CR>

Then it works correctly at MacVim startup, but I don't want to have to hold both ctrl+alt. Only keybindings with alt alone don't work.

I've tried playing with the macmeta setting, it doesn't make any difference. I shouldn't need macmeta anyway according to the help page:

        Note: Some keys (e.g. <M-F1>, <M-Tab>, <M-Return>, <M-Left>) can be
        bound with the Meta flag even when this option is disabled, but this
        is not the case for the majority of keys (e.g. <M-a>, <M-`>).

I'm kind of stumped at this point. Any help is appreciated.

Thanks,
Shaun

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Mapping alt+arrow keys?

Tony Mechelynck
I'm redirecting this conversation to vim_use which I think is more appropriate than vim_mac in this case.

On Wednesday, October 7, 2015 at 2:02:30 AM UTC+2, Shaun Friedle wrote:

> Hi,
>
> I'm having difficultly mapping alt + the arrow keys at startup in MacVim.
>
> So, I have this in my .vimrc in order to move between windows:
>
> map <M-Up> :wincmd k<CR>
> map <M-Down> :wincmd j<CR>
> map <M-Left> :wincmd h<CR>
> map <M-Right> :wincmd l<CR>
>
> But this doesn't work in MacVim at startup, alt+left/right navigate to previous/next word and alt+up/down seem to navigate to previous/next paragraph. It does work if I do:
>
> :source ~/.vimrc
>
> So somehow if my execute my vimrc after MacVim has started then the mapping works correctly. Everything else in my vimrc works normally without having to manually source it including other key mappings. I've also tried deleting everything else in my vimrc except those 4 lines and it still doesn't work. If I change the maps to:
>
> map <C-M-Up> :wincmd k<CR>
> map <C-M-Down> :wincmd j<CR>
> map <C-M-Left> :wincmd h<CR>
> map <C-M-Right> :wincmd l<CR>
>
> Then it works correctly at MacVim startup, but I don't want to have to hold both ctrl+alt. Only keybindings with alt alone don't work.
>
> I've tried playing with the macmeta setting, it doesn't make any difference. I shouldn't need macmeta anyway according to the help page:
>
> Note: Some keys (e.g. <M-F1>, <M-Tab>, <M-Return>, <M-Left>) can be
> bound with the Meta flag even when this option is disabled, but this
> is not the case for the majority of keys (e.g. <M-a>, <M-`>).
>
> I'm kind of stumped at this point. Any help is appreciated.
>
> Thanks,
> Shaun
If you don't want to hold both Ctrl and Alt, well, choose some other {lhs}. Here is an example, but it is thertainly not the only possibility:

:map <F6> <C-W>h
:map <F7> <C-W>j
:map <F8> <C-W>k
:map <F9> <C-W>l

Or if Ctrl-W is easy for you to type, just use it instead of :wincmd, that's a built-in key binding (in Vim compiled with +windows, of course), no mapping needed.

See :help :wincmd

What I use is, navigate to the next or previous window rather than geographically, as follows:
" move to next window with F11, previous window with Shift-F11
" These will accept a count (in Normal mode at least)
" to go to Nth window from top, not Nth previous or next window
:map <F11> <C-W>w
:map <S-F11> <C-W>W
:map! <F11> <C-O><C-W>w
:map! <S-F11> <C-O><C-W>W


Best regards,
Tony.

--
--
You received this message from the "vim_mac" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_mac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.