Commands for moving line-wise and block-wise lines and characters, both vertically and horizontally.
move_block_horizontally.mp4
move_block_vertically.mp4
move_line_vertically.mp4
This plugin works with NeoVim v0.5 or later.
use "hinell/move.nvim"
Plug "hinell/move.nvim"
"hinell/move.nvim";
"hinell/move.nvim"
The plugin provides the following commands. Every command accept [0-9]+
number:
Command | Description | Modes |
---|---|---|
MoveLine | Moves a line up or down | Normal |
MoveBlock | Moves a selected block of text, up or down | Visual |
MoveWord | Moves the word under the cursor forwards or backwards | Normal |
MoveHChar | Moves the character under the cursor, left or right | Normal |
MoveHBlock | Moves a visual area, left or right | Visual |
NO keybindings are setup by default.
Alternatively, you can setup ALT+... hotkeys manually:
local opts = { noremap = true, silent = true }
-- Normal-mode commands
vim.keymap.set('n', '<A-Up>' ,':MoveLine 1<CR>', opts)
vim.keymap.set('n', '<A-Down>' ,':MoveLine -1<CR>', opts)
vim.keymap.set('n', '<A-S-Left>' ,':MoveWord -1<CR>', opts)
vim.keymap.set('n', '<A-S-Right>' ,':MoveWord 1<CR>', opts)
-- Visual-mode commands
vim.keymap.set('x', '<A-Up>' , ':MoveBlock 1<CR>', opts)
vim.keymap.set('x', '<A-Down>' , ':MoveBlock -1<CR>', opts)
vim.keymap.set('v', '<A-Left>' , ':MoveHBlock -1<CR>', opts)
vim.keymap.set('v', '<A-Right>', ':MoveHBlock 1<CR>', opts)
...
Not recommended.
" Normal-mode commands
nnoremap <silent> <A-j> :MoveLine 1<CR>
nnoremap <silent> <A-k> :MoveLine -1<CR>
nnoremap <silent> <A-l> :MoveHChar 1<CR>
nnoremap <silent> <A-h> :MoveHChar -1<CR>
" Visual-selection-mode commands
xnoremap <silent> <A-j> :MoveBlock 1<CR>
xnoremap <silent> <A-k> :MoveBlock -1<CR>
vnoremap <silent> <A-l> :MoveHBlock 1<CR>
vnoremap <silent> <A-h> :MoveHBlock -1<CR>
There is an original and more feature rich plugin (written in VimScript):
Original author: thanks to fedepujol@github.com
. Most of the code can be is attributed to him.
I made a few impromements over fedepujol
's work: added plugin/init.lua
for better compatibility and updated media.
September 15, 2023