[General] Fixes

This commit is contained in:
2025-11-12 15:27:33 +01:00
parent ae8c9a875d
commit afd1633b4a
6 changed files with 100 additions and 98 deletions

View File

@@ -1,19 +1,17 @@
return { return {
-- git buffer integration -- git buffer integration
"lewis6991/gitsigns.nvim", "lewis6991/gitsigns.nvim",
event = "BufRead", event = "BufRead",
config = function() opts = {
require("gitsigns").setup({ count_chars = { "¹", "²", "³", "", "", "", "", "", "", ["+"] = "" },
count_chars = { "¹", "²", "³", "", "", "", "", "", "", ["+"] = "" }, signs = {
signs = { add = { show_count = true },
add = { show_count = true }, change = { show_count = true },
change = { show_count = true }, delete = { show_count = true },
delete = { show_count = true }, topdelete = { show_count = true },
topdelete = { show_count = true }, changedelete = { show_count = true },
changedelete = { show_count = true }, untracked = { show_count = true },
untracked = { show_count = true }, },
}, numhl = true,
numhl = true, },
})
end,
} }

View File

@@ -1,8 +1,6 @@
return { return {
-- open file at previous position -- open file at previous position
"ethanholz/nvim-lastplace", "ethanholz/nvim-lastplace",
event = { "BufReadPre", "BufNewFile" }, event = { "BufReadPre", "BufNewFile" },
config = function() opts = {},
require("nvim-lastplace").setup({})
end,
} }

View File

@@ -1,18 +1,19 @@
local utils = require("utils")
return { return {
opts = {}, opts = {},
"fedepujol/move.nvim", "fedepujol/move.nvim",
keys = { keys = {
{ "<A-S-k>", ":MoveLine(-1)<CR>", desc = "Move line up" }, { "<A-S-k>", utils.run_vim_cmd("MoveLine(-1)"), desc = "Move line up" },
{ "<A-S-j>", ":MoveLine(1)<CR>", desc = "Move line down" }, { "<A-S-j>", utils.run_vim_cmd("MoveLine(1)"), desc = "Move line down" },
{ "<leader>mk", ":MoveLine(-1)<CR>", desc = "Move line up" }, { "<leader>mk", utils.run_vim_cmd("MoveLine(-1)"), desc = "Move line up" },
{ "<leader>mj", ":MoveLine(1)<CR>", desc = "Move line down" }, { "<leader>mj", utils.run_vim_cmd("MoveLine(1)"), desc = "Move line down" },
-- Move blocks in visual mode -- Move blocks in visual mode
{ "<A-k>", ":MoveBlock(-1)<CR>", desc = "Move line up" }, { "<A-k>", utils.run_vim_cmd("MoveBlock(-1)"), desc = "Move line up" },
{ "<A-j>", ":MoveBlock(1)<CR>", desc = "Move line down" }, { "<A-j>", utils.run_vim_cmd("MoveBlock(1)"), desc = "Move line down" },
-- Move lines in insert mode -- Move lines in insert mode
{ "<A-k>", "<C-o>:MoveLine(-1)<CR>", desc = "Move line up" }, { "<A-k>", utils.run_vim_cmd("MoveLine(-1)"), desc = "Move line up" },
{ "<A-j>", "<C-o>:MoveLine(1)<CR>", desc = "Move line down" }, { "<A-j>", utils.run_vim_cmd("MoveLine(1)"), desc = "Move line down" },
}, },
} }

View File

@@ -1,16 +1,17 @@
local utils = require("utils")
return { return {
"smoka7/multicursors.nvim", "smoka7/multicursors.nvim",
dependencies = { dependencies = {
"nvimtools/hydra.nvim", "nvimtools/hydra.nvim",
}, },
opts = {}, opts = {},
cmd = { "MCstart", "MCvisual", "MCclear", "MCpattern", "MCvisualPattern", "MCunderCursor" }, cmd = { "MCstart", "MCvisual", "MCclear", "MCpattern", "MCvisualPattern", "MCunderCursor" },
keys = { keys = {
{ {
mode = { "v", "n" }, mode = { "v", "n" },
"<leader><leader>c", "<leader><leader>c",
"<cmd>MCstart<cr>", utils.run_vim_cmd("MCstart(-1)"),
desc = "Create a selection for selected text or word under the cursor", desc = "Create a selection for selected text or word under the cursor",
}, },
}, },
} }

View File

@@ -2,7 +2,5 @@ return {
"kylechui/nvim-surround", "kylechui/nvim-surround",
version = "*", version = "*",
event = "InsertEnter", event = "InsertEnter",
config = function() opts = {}
require("nvim-surround").setup()
end,
} }

View File

@@ -3,56 +3,62 @@
local M = {} local M = {}
M.opts = function(desc) M.opts = function(desc)
if desc then if desc then
return { noremap = true, silent = true, desc = desc } return { noremap = true, silent = true, desc = desc }
else else
return { noremap = true, silent = true } return { noremap = true, silent = true }
end end
end
M.run_vim_cmd = function(cmd)
return function()
vim.cmd(cmd)
end
end end
M.sudo_exec = function(cmd, print_output) M.sudo_exec = function(cmd, print_output)
vim.fn.inputsave() vim.fn.inputsave()
local password = vim.fn.inputsecret("Password: ") local password = vim.fn.inputsecret("Password: ")
vim.fn.inputrestore() vim.fn.inputrestore()
if not password or #password == 0 then if not password or #password == 0 then
print("Invalid password, sudo aborted") print("Invalid password, sudo aborted")
return false return false
end end
local out = vim.fn.system(string.format("sudo -p '' -S %s", cmd), password) local out = vim.fn.system(string.format("sudo -p '' -S %s", cmd), password)
if vim.v.shell_error ~= 0 then if vim.v.shell_error ~= 0 then
print("\r\n") print("\r\n")
print(out) print(out)
return false return false
end end
if print_output then if print_output then
print("\r\n", out) print("\r\n", out)
end end
return true return true
end end
M.sudo_write = function(tmpfile, filepath) M.sudo_write = function(tmpfile, filepath)
if not tmpfile then if not tmpfile then
tmpfile = vim.fn.tempname() tmpfile = vim.fn.tempname()
end end
if not filepath then if not filepath then
filepath = vim.fn.expand("%") filepath = vim.fn.expand("%")
end end
if not filepath or #filepath == 0 then if not filepath or #filepath == 0 then
print("E32: No file name") print("E32: No file name")
return return
end end
-- `bs=1048576` is equivalent to `bs=1M` for GNU dd or `bs=1m` for BSD dd -- `bs=1048576` is equivalent to `bs=1M` for GNU dd or `bs=1m` for BSD dd
-- Both `bs=1M` and `bs=1m` are non-POSIX -- Both `bs=1M` and `bs=1m` are non-POSIX
local cmd = string.format("dd if=%s of=%s bs=1048576", vim.fn.shellescape(tmpfile), vim.fn.shellescape(filepath)) local cmd = string.format("dd if=%s of=%s bs=1048576", vim.fn.shellescape(tmpfile), vim.fn.shellescape(filepath))
-- no need to check error as this fails the entire function -- no need to check error as this fails the entire function
vim.api.nvim_exec(string.format("write! %s", tmpfile), true) vim.api.nvim_exec(string.format("write! %s", tmpfile), true)
if M.sudo_exec(cmd) then if M.sudo_exec(cmd) then
-- refreshes the buffer and prints the "written" message -- refreshes the buffer and prints the "written" message
vim.cmd.checktime() vim.cmd.checktime()
-- exit command mode -- exit command mode
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
end end
vim.fn.delete(tmpfile) vim.fn.delete(tmpfile)
end end
return M return M