matze / vim-move

Plugin to move lines and selections up and down
http://www.vim.org/scripts/script.php?script_id=4687
MIT License
1.21k stars 56 forks source link

How to use this Plugin with arrow keys? #64

Closed maxreuben closed 2 years ago

maxreuben commented 2 years ago

How can i retool this plugin to make it use arrow keys instead of hjkl? Is it possible? I don't know Vimscript so I can't really tell.

matze commented 2 years ago

Disable auto-mapping and then bind <Up> and <Down> as usual, i.e.

let g:move_map_keys = 0

vmap <Down> <Plug>MoveBlockDown
vmap <Up> <Plug>MoveBlockUp
nmap <Down> <Plug>MoveLineDown
nmap <Up> <Plug>MoveLineUp
maxreuben commented 2 years ago

Thank you for your help.

maxreuben commented 2 years ago

Neither Alt nor Ctrl keys are getting mapped in any of my terminals (alacritty, gnome-terminal, tabby). Is there a way to prevent the terminal from prefixing the ESC character somehow? Or at least a workaround so that that it can be mapped in vim? I tried this:

 map <ESC>[1;5B <A-Down>
 map <ESC>[1;5A <A-Up>
 map! <ESC>[1;5B <A-Down>
 map! <ESC>[1;5A <A-Up>

 let g:move_map_keys = 0

 vmap <A-Down> <Plug>MoveBlockDown
 vmap <A-Up>   <Plug>MoveBlockUp
 nmap <A-Down> <Plug>MoveLineDown
 nmap <A-Up>   <Plug>MoveLineUp

But it didn't work.

matze commented 2 years ago

You can see what sequence is sent by going into insert mode, typing C-v and then typing whatever you are interested in. If I type Alt-Up in gnome-terminal I get <M-Up>.

maxreuben commented 2 years ago

Thanks, I figured it out.