Added binds for moving lines of code

I really like the feature from Vs Code that allows you to use the keys on your keyboard to move pieces of code relative to the rest of the code around, I think it's a handy feature that will help well when editing code
pull/2830/head
Timur 2 weeks ago committed by GitHub
parent 156eeef8ec
commit c2631e3af9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -51,6 +51,38 @@ map("n", "<leader>/", function()
require("Comment.api").toggle.linewise.current()
end, { desc = "comment toggle" })
--Move line
local function move_line(op)
return function()
local start = op == "+" and 1 or 2
local count = vim.v.count
local times = count == 0 and start or (op == "+" and count or count + 1)
local ok, _ = pcall(vim.cmd.move, op .. times)
if ok then
vim.cmd.norm("==")
end
end
end
local function move_selected(op)
return function()
local restore_autocmd = u.disable_autocmd("toggle_relnum")
local start = op == "+" and "" or 2
local count = vim.v.count
local times = count == 0 and start or (op == "+" and count or count + 1)
local mark = op == "+" and "'>" or "'<"
vim.api.nvim_feedkeys(vim.keycode(":move" .. mark .. op .. times .. "<Cr>gv=gv"), "n", true)
restore_autocmd()
end
end
map("n", "<A-j>", move_line("+"), { silent = true, desc = "Move line to Top" })
map("n", "<A-k>", move_line("-"), { silent = true, desc = "Move line to Down" })
map("x", "<A-j>", move_selected("+"), { silent = true, desc = "Move Group of line to Top" })
map("x", "<A-k>", move_selected("-"), { silent = true, desc = "Move Group of line to Down" })
map(
"v",
"<leader>/",

Loading…
Cancel
Save