• Stars
    star
    213
  • Rank 184,497 (Top 4 %)
  • Language
    Lua
  • Created about 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Gain the power to move lines and blocks and auto-indent them!

move.nvim

Gain the power to move lines and blocks!

Vertical Movement

vert_line

vert_block

Horizontal Movement

hor_char

hor_block

Word Movement

word

Requirements

This plugin works with NeoVim v0.5 or later.

Installation

use 'fedepujol/move.nvim'
Plug 'fedepujol/move.nvim'
'fedepujol/move.nvim';

Usage

The plugin provides the following commands:

Command Description Mode
MoveLine Moves a line up or down Normal
MoveHChar Moves the character under the cursor, left or right Normal
MoveWord Moves the word under the cursor forwards or backwards Normal
MoveBlock Moves a selected block of text, up or down Visual
MoveHBlock Moves a visual area, left or right Visual

⌨️ Mappings

VimScript

" 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>
nnoremap <silent> <leader>wf :MoveWord(1)<CR>
nnoremap <silent> <leader>wb :MoveWord(-1)<CR>

" Visual-mode commands
vnoremap <silent> <A-j> :MoveBlock(1)<CR>
vnoremap <silent> <A-k> :MoveBlock(-1)<CR>
vnoremap <silent> <A-l> :MoveHBlock(1)<CR>
vnoremap <silent> <A-h> :MoveHBlock(-1)<CR>

Lua

local opts = { noremap = true, silent = true }
-- Normal-mode commands
vim.keymap.set('n', '<A-j>', ':MoveLine(1)<CR>', opts)
vim.keymap.set('n', '<A-k>', ':MoveLine(-1)<CR>', opts)
vim.keymap.set('n', '<A-h>', ':MoveHChar(-1)<CR>', opts)
vim.keymap.set('n', '<A-l>', ':MoveHChar(1)<CR>', opts)
vim.keymap.set('n', '<leader>wf', ':MoveWord(1)<CR>', opts)
vim.keymap.set('n', '<leader>wb', ':MoveWord(-1)<CR>', opts)

-- Visual-mode commands
vim.keymap.set('v', '<A-j>', ':MoveBlock(1)<CR>', opts)
vim.keymap.set('v', '<A-k>', ':MoveBlock(-1)<CR>', opts)
vim.keymap.set('v', '<A-h>', ':MoveHBlock(-1)<CR>', opts)
vim.keymap.set('v', '<A-l>', ':MoveHBlock(1)<CR>', opts)

Integration

Legendary.nvim

Thanks to hinell to point this out:

Note: Don't set up the keys like above if you're using legendary

local opts = { noremap = true }
require('legendary').setup({
    keymaps = {
        { "<A-k>", ":MoveLine -1", description = "Line: move up", opts },
        { "<A-j>", ":MoveLine 1", description = "Line: move down", opts },
        ...
    }
})

Mention

There is an original and more feature rich plugin (written in VimScript):

vim-move.