NvChad / NvChad

Blazing fast Neovim config providing solid defaults and a beautiful UI, enhancing your neovim experience.
https://nvchad.com/
GNU General Public License v3.0
24.47k stars 2.11k forks source link

Moving blocks in visual mode with NvChad #2351

Closed d13g0 closed 1 year ago

d13g0 commented 1 year ago

Not sure where to ask this. I am trying to select lines in visual mode and move them with a command. I would normally do:

local keymap = vim.api.nvim_set_keymap
local opts = {noremap = true, silent= false} 
keymap("v", "<C-j>", ":m .+1<CR>==", ...)
keymap("v", "<C-k>", ":m .-2<CR>==", ...)

So I am trying to do it the NvChad way:

So I created a mappings.lua file under /lua/custom/mappings.lua, and I made sure it is required from /lua/custom/chadrc.lua (as in the example configuration)

M.mappings = require "custom.mappings"
...
return M

It looks like this:


M.general = {
  v = {
    ["<C-j>"] = { ":m '>+1<CR>gv==gv", "Move block one line down" },
    ["<C-k>"] = { ":m '<-2<CR>gv==gv", "Move block one line up" },
  }

}
return M

But it doesn't work! What can I do?

d13g0 commented 1 year ago

I found a solution:

M.general = {
  v = {
    ["<C-j>"] = { ":m '>+1<CR>gv-gv", "Move block one line down" },
    ["<C-k>"] = { ":m '<-2<CR>gv-gv", "Move block one line up" },
  }

}
return M