What I want to do
I want to map <S-A-j> and <S-A-k> on a Mac keyboard to move selected lines up and down.
So, I map:
" Move selected lines
xnoremap <S-A-j> :m'>+<CR>gv=gv
xnoremap <S-A-k> :m-2<CR>gv=gv
But it's not working, so type the <S-A-j> keys in insert mode:
- For
<S-A-j>it's writingÍ - For
<S-A-k>it's writingË
So I try this :
xnoremap Í :m'>+<CR>gv=gv
xnoremap Ë :m-2<CR>gv=gv
It's perfectly working. The problem is that is not easy to read and it feels like a bug right?
What I try
Mappings
"xnoremap <S-j> <A-j> :m'>+<CR>gv=gv
"xnoremap <S-k> <A-k> :m-2<CR>gv=gv
"xnoremap <S-J> <A-J> :m'>+<CR>gv=gv
"xnoremap <S-K> <A-K> :m-2<CR>gv=gv
"xnoremap <S-j><A-j> :m'>+<CR>gv=gv
"xnoremap <S-k><A-k> :m-2<CR>gv=gv
"xnoremap <S-j> <M-j> :m'>+<CR>gv=gv
"xnoremap <S-k> <M-k> :m-2<CR>gv=gv
Differents Vim
MacVim and Neovim
Terminals
I try to run on the default terminal.
I also configure my Iterm2 terminal with pref > profile > keys -> option key=Esc+
My environment
- Apple M1 Pro
- macOs Ventura 13.4
- Iterm2
- zsh
- level: I use Ideavim frequently on Android Studio but don't really understand Vim and how it works.
My Solution
Remap your AZERTY input to make understand Vim what you want
map Í <S-A-j>
map Ë <S-A-k>
xnoremap <S-A-j> :m'>+<CR>gv=gv
xnoremap <S-A-k> :m-2<CR>gv=gv
It will be interesting to remap all the keys from AZERTY to QWERTY for specials key (with Alt or/and Ctrl) on a different file and then source it. I didn't find any error at the moment, in insert mode he recognizes well the right character.
This is mostly a Mac thing with international keyboards.
Vim doesn't know that you pressed
Ctrl,Opt, andjtogether: all it sees isÍ, so that's all you can use in your mapping.Moreover,
Íis actually produced byOpt+j. TheCtrlmodifier does nothing, here.So… what are your options?
Use the actual character produced by the key combination:
Pros:
Cons:
Set up your terminal emulator to use "Option as Meta" (Terminal.app) or "Esc+" (iTerm.app) and use
<Esc>in your mapping:Pros:
Cons: