Skip to content

Horizontal Block Move not registered as a command... #33

@wytchblade

Description

@wytchblade

Hello @fedepujol ! Thank you very much for working on this extremely useful plugin. I wanted to reach out to you because I am running into this error when attempting to use horizontal block move:

E492: Not an editor command: '<,'>MoveHBlock(-1)

My configuration is relatively simple ( I only use Block movement from the plugin, btw, which is why everything else is disabled or commented out...I need the keymaps for other stuff!)

return {
  "fedepujol/move.nvim",
  keys = {
    -- Normal Mode
    -- { "<A-j>", ":MoveLine(1)<CR>", desc = "Move Line Up" },
    -- { "<A-k>", ":MoveLine(-1)<CR>", desc = "Move Line Down" },
    -- { "<A-h>", ":MoveHChar(-1)<CR>", desc = "Move Character Left" },
    -- { "<A-l>", ":MoveHChar(1)<CR>", desc = "Move Character Right" },
    { "<C-b>", ":MoveWord(-1)<CR>", mode = { "n" }, desc = "Move Word Left" },
    { "<C-w>", ":MoveWord(1)<CR>", mode = { "n" }, desc = "Move Word Right" },
    -- Visual Mode
    { "<C-j>", ":MoveBlock(1)<CR>", mode = { "v" }, desc = "Move Block Up" },
    { "<C-k>", ":MoveBlock(-1)<CR>", mode = { "v" }, desc = "Move Block Down" },
    -- { "<C-h>", ":MoveHBlock(-1)<CR>", mode = { "v" }, desc = "Move Block Left" },
    -- { "<C-l>", ":MoveHBlock(1)<CR>", mode = { "v" }, desc = "Move Block Right" },
  },
  opts = {
    line = {
      enable = false, -- Enables line movement
      indent = false  -- Toggles indentation
    },
    block = {
      enable = true, -- Enables block movement
      indent = true  -- Toggles indentation
    },
    word = {
      enable = false, -- Enables word movement
    },
    char = {
      enable = false -- Enables char movement
    }
    -- Config here
  }
}

In my keymaps.lua file, I have the following lines of code:

--  Move blocks horizontally (left/right)
vim.keymap.set('v', '<S-h>', ':MoveHBlock(-1)<CR>', opts)
vim.keymap.set('v', '<S-l>', ':MoveHBlock(1)<CR>', opts)

-- Keep cursor centered when scrolling
map("n", "<C-d>", "<C-d>zz", opts)
map("n", "<C-u>", "<C-u>zz", opts)

-- Move selected line / block of text in visual mode
-- map("v", "J", ":m '>+1<CR>gv=gv", opts)
vim.keymap.set('v', '<C-k>', ':MoveBlock(-1)<CR>', opts)
-- map("v", "K", ":m '<-2<CR>gv=gv", opts)
vim.keymap.set('v', '<C-j>', ':MoveBlock(1)<CR>', opts)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions