diff --git a/nvim/lua/plugins/nav/gitsigns.lua b/nvim/lua/plugins/nav/gitsigns.lua index 9f9ba7d..3f702c4 100755 --- a/nvim/lua/plugins/nav/gitsigns.lua +++ b/nvim/lua/plugins/nav/gitsigns.lua @@ -1,19 +1,17 @@ return { - -- git buffer integration - "lewis6991/gitsigns.nvim", - event = "BufRead", - config = function() - require("gitsigns").setup({ - count_chars = { "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹", ["+"] = "⁺" }, - signs = { - add = { show_count = true }, - change = { show_count = true }, - delete = { show_count = true }, - topdelete = { show_count = true }, - changedelete = { show_count = true }, - untracked = { show_count = true }, - }, - numhl = true, - }) - end, + -- git buffer integration + "lewis6991/gitsigns.nvim", + event = "BufRead", + opts = { + count_chars = { "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹", ["+"] = "⁺" }, + signs = { + add = { show_count = true }, + change = { show_count = true }, + delete = { show_count = true }, + topdelete = { show_count = true }, + changedelete = { show_count = true }, + untracked = { show_count = true }, + }, + numhl = true, + }, } diff --git a/nvim/lua/plugins/nav/lastplace.lua b/nvim/lua/plugins/nav/lastplace.lua index 7c0c3df..69e34bf 100755 --- a/nvim/lua/plugins/nav/lastplace.lua +++ b/nvim/lua/plugins/nav/lastplace.lua @@ -1,8 +1,6 @@ return { - -- open file at previous position - "ethanholz/nvim-lastplace", - event = { "BufReadPre", "BufNewFile" }, - config = function() - require("nvim-lastplace").setup({}) - end, + -- open file at previous position + "ethanholz/nvim-lastplace", + event = { "BufReadPre", "BufNewFile" }, + opts = {}, } diff --git a/nvim/lua/plugins/util/move.lua b/nvim/lua/plugins/util/move.lua index c56e435..89cb456 100755 --- a/nvim/lua/plugins/util/move.lua +++ b/nvim/lua/plugins/util/move.lua @@ -1,18 +1,19 @@ +local utils = require("utils") return { - opts = {}, - "fedepujol/move.nvim", - keys = { - { "", ":MoveLine(-1)", desc = "Move line up" }, - { "", ":MoveLine(1)", desc = "Move line down" }, - { "mk", ":MoveLine(-1)", desc = "Move line up" }, - { "mj", ":MoveLine(1)", desc = "Move line down" }, + opts = {}, + "fedepujol/move.nvim", + keys = { + { "", utils.run_vim_cmd("MoveLine(-1)"), desc = "Move line up" }, + { "", utils.run_vim_cmd("MoveLine(1)"), desc = "Move line down" }, + { "mk", utils.run_vim_cmd("MoveLine(-1)"), desc = "Move line up" }, + { "mj", utils.run_vim_cmd("MoveLine(1)"), desc = "Move line down" }, - -- Move blocks in visual mode - { "", ":MoveBlock(-1)", desc = "Move line up" }, - { "", ":MoveBlock(1)", desc = "Move line down" }, + -- Move blocks in visual mode + { "", utils.run_vim_cmd("MoveBlock(-1)"), desc = "Move line up" }, + { "", utils.run_vim_cmd("MoveBlock(1)"), desc = "Move line down" }, - -- Move lines in insert mode - { "", ":MoveLine(-1)", desc = "Move line up" }, - { "", ":MoveLine(1)", desc = "Move line down" }, - }, + -- Move lines in insert mode + { "", utils.run_vim_cmd("MoveLine(-1)"), desc = "Move line up" }, + { "", utils.run_vim_cmd("MoveLine(1)"), desc = "Move line down" }, + }, } diff --git a/nvim/lua/plugins/util/multicursors.lua b/nvim/lua/plugins/util/multicursors.lua index d72f8a2..e0eeaaa 100755 --- a/nvim/lua/plugins/util/multicursors.lua +++ b/nvim/lua/plugins/util/multicursors.lua @@ -1,16 +1,17 @@ +local utils = require("utils") return { - "smoka7/multicursors.nvim", - dependencies = { - "nvimtools/hydra.nvim", - }, - opts = {}, - cmd = { "MCstart", "MCvisual", "MCclear", "MCpattern", "MCvisualPattern", "MCunderCursor" }, - keys = { - { - mode = { "v", "n" }, - "c", - "MCstart", - desc = "Create a selection for selected text or word under the cursor", - }, - }, + "smoka7/multicursors.nvim", + dependencies = { + "nvimtools/hydra.nvim", + }, + opts = {}, + cmd = { "MCstart", "MCvisual", "MCclear", "MCpattern", "MCvisualPattern", "MCunderCursor" }, + keys = { + { + mode = { "v", "n" }, + "c", + utils.run_vim_cmd("MCstart(-1)"), + desc = "Create a selection for selected text or word under the cursor", + }, + }, } diff --git a/nvim/lua/plugins/util/surround.lua b/nvim/lua/plugins/util/surround.lua index 2397f97..b56af50 100755 --- a/nvim/lua/plugins/util/surround.lua +++ b/nvim/lua/plugins/util/surround.lua @@ -2,7 +2,5 @@ return { "kylechui/nvim-surround", version = "*", event = "InsertEnter", - config = function() - require("nvim-surround").setup() - end, + opts = {} } diff --git a/nvim/lua/utils.lua b/nvim/lua/utils.lua index 6a880dc..cadad36 100755 --- a/nvim/lua/utils.lua +++ b/nvim/lua/utils.lua @@ -3,56 +3,62 @@ local M = {} M.opts = function(desc) - if desc then - return { noremap = true, silent = true, desc = desc } - else - return { noremap = true, silent = true } - end + if desc then + return { noremap = true, silent = true, desc = desc } + else + return { noremap = true, silent = true } + end +end + +M.run_vim_cmd = function(cmd) + return function() + vim.cmd(cmd) + end end M.sudo_exec = function(cmd, print_output) - vim.fn.inputsave() - local password = vim.fn.inputsecret("Password: ") - vim.fn.inputrestore() - if not password or #password == 0 then - print("Invalid password, sudo aborted") - return false - end - local out = vim.fn.system(string.format("sudo -p '' -S %s", cmd), password) - if vim.v.shell_error ~= 0 then - print("\r\n") - print(out) - return false - end - if print_output then - print("\r\n", out) - end - return true + vim.fn.inputsave() + local password = vim.fn.inputsecret("Password: ") + vim.fn.inputrestore() + if not password or #password == 0 then + print("Invalid password, sudo aborted") + return false + end + local out = vim.fn.system(string.format("sudo -p '' -S %s", cmd), password) + if vim.v.shell_error ~= 0 then + print("\r\n") + print(out) + return false + end + if print_output then + print("\r\n", out) + end + return true end M.sudo_write = function(tmpfile, filepath) - if not tmpfile then - tmpfile = vim.fn.tempname() - end - if not filepath then - filepath = vim.fn.expand("%") - end - if not filepath or #filepath == 0 then - print("E32: No file name") - return - end - -- `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 - 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 - vim.api.nvim_exec(string.format("write! %s", tmpfile), true) - if M.sudo_exec(cmd) then - -- refreshes the buffer and prints the "written" message - vim.cmd.checktime() - -- exit command mode - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", true) - end - vim.fn.delete(tmpfile) + if not tmpfile then + tmpfile = vim.fn.tempname() + end + if not filepath then + filepath = vim.fn.expand("%") + end + if not filepath or #filepath == 0 then + print("E32: No file name") + return + end + -- `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 + 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 + vim.api.nvim_exec(string.format("write! %s", tmpfile), true) + if M.sudo_exec(cmd) then + -- refreshes the buffer and prints the "written" message + vim.cmd.checktime() + -- exit command mode + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", true) + end + vim.fn.delete(tmpfile) end return M