Format config

This commit is contained in:
Janis Hutz 2025-06-05 11:33:49 +02:00
parent 5870ed5fc5
commit 4aa0c54fc4
35 changed files with 867 additions and 856 deletions

View File

@ -11,16 +11,15 @@ if not vim.loop.fs_stat(lazypath) then
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
require("lazy").setup({ require("lazy").setup({
spec = { spec = {
{ import = "plugins.nav" }, { import = "plugins.nav" },
{ import = "plugins.lsp" }, { import = "plugins.lsp" },
{ import = "plugins.style" }, { import = "plugins.style" },
{ import = "plugins.util" }, { import = "plugins.util" },
{ import = "plugins.testing" } { import = "plugins.testing" },
}, },
change_detection = { change_detection = {
notify = false, -- dont notify when plugins are changed notify = false, -- dont notify when plugins are changed
} },
}) })

View File

@ -16,8 +16,8 @@ vim.opt.breakindent = true
vim.opt.linebreak = true vim.opt.linebreak = true
-- folding -- folding
vim.wo.foldmethod = 'expr' vim.wo.foldmethod = "expr"
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
-- line numbers -- line numbers
vim.wo.number = true vim.wo.number = true

View File

@ -86,7 +86,7 @@ return {
-- Otherwise, fallback (insert a tab character) -- Otherwise, fallback (insert a tab character)
fallback() fallback()
end end
end, { "i", "s" }) end, { "i", "s" }),
}), }),
-- sources for autocompletion -- sources for autocompletion
@ -95,7 +95,7 @@ return {
{ name = "luasnip" }, -- snippets { name = "luasnip" }, -- snippets
{ name = "buffer" }, -- text within current buffer { name = "buffer" }, -- text within current buffer
{ name = "path" }, -- file system paths { name = "path" }, -- file system paths
{ name = 'nvim_lsp_signature_help' }, -- signature help { name = "nvim_lsp_signature_help" }, -- signature help
}), }),
formatting = { formatting = {

View File

@ -1,12 +1,3 @@
return { return {
'L3MON4D3/LuaSnip', "L3MON4D3/LuaSnip",
-- config = function()
-- local luasnip = require('luasnip')
-- -- luasnip.setup({
-- -- region_check_events = "CursorMoved",
-- -- delete_check_events = "TextChanged",
-- -- })
--
-- require("luasnip.loaders.from_vscode").load({paths = "~/.config/nvim/my_snippets"})
-- end
} }

View File

@ -1,7 +1,10 @@
-- ┌ ┐
-- │ Formatting, diagnostics │
-- └ ┘
return { return {
"nvimtools/none-ls.nvim", "nvimtools/none-ls.nvim",
dependencies = { dependencies = {
'nvimtools/none-ls-extras.nvim' "nvimtools/none-ls-extras.nvim",
}, },
config = function() config = function()
local null_ls = require("null-ls") local null_ls = require("null-ls")
@ -46,9 +49,9 @@ return {
null_ls.builtins.formatting.shfmt, null_ls.builtins.formatting.shfmt,
null_ls.builtins.formatting.asmfmt, null_ls.builtins.formatting.asmfmt,
null_ls.builtins.code_actions.proselint, null_ls.builtins.code_actions.proselint,
require( 'none-ls.diagnostics.eslint_d' ), require("none-ls.diagnostics.eslint_d"),
require( 'none-ls.code_actions.eslint_d' ), require("none-ls.code_actions.eslint_d"),
require( 'none-ls.formatting.eslint_d' ), require("none-ls.formatting.eslint_d"),
null_ls.builtins.formatting.black, null_ls.builtins.formatting.black,
}, },
}) })

View File

@ -41,13 +41,13 @@ return {
"vue", "vue",
"xml", "xml",
"yaml", "yaml",
"zathurarc" "zathurarc",
}, },
sync_install = false, sync_install = false,
highlight = { highlight = {
enable = true, enable = true,
disable = { "tex" } disable = { "tex" },
}, },
}) })
end, end,

View File

@ -2,14 +2,14 @@ return {
"lervag/vimtex", "lervag/vimtex",
config = function() config = function()
-- vimtex settings -- vimtex settings
-- vim.g.vimtex_view_method = 'startup' -- PDF viewer (example: zathura, or use 'skim' for macOS) -- vim.g.vimtex_view_method = 'zathura' -- PDF viewer (example: zathura, or use 'skim' for macOS)
vim.g.vimtex_compiler_method = 'latexmk' -- Use latexmk for compilation vim.g.vimtex_compiler_method = "latexmk" -- Use latexmk for compilation
vim.g.vimtex_fold_enabled = 1 -- Enable folding for LaTeX sections vim.g.vimtex_fold_enabled = 1 -- Enable folding for LaTeX sections
vim.g.vimtex_quickfix_mode = 0 -- Disable quickfix mode for compilation errors vim.g.vimtex_quickfix_mode = 0 -- Disable quickfix mode for compilation errors
-- Key Mappings for LaTeX workflow
vim.api.nvim_set_keymap('n', '<leader>lc', ':VimtexCompile<CR>', {}) -- Compile LaTeX file
vim.api.nvim_set_keymap('n', '<leader>lv', ':VimtexView<CR>', {}) -- View compiled PDF
vim.api.nvim_set_keymap('n', '<leader>lq', ':VimtexStop<CR>', {}) -- Stop compilation
end -- ── Key Mappings for LaTeX workflow ──────────────────────────────
vim.api.nvim_set_keymap("n", "<leader>lc", ":VimtexCompile<CR>", {}) -- Compile LaTeX file
vim.api.nvim_set_keymap("n", "<leader>lv", ":VimtexView<CR>", {}) -- View compiled PDF
vim.api.nvim_set_keymap("n", "<leader>lq", ":VimtexStop<CR>", {}) -- Stop compilation
end,
} }

View File

@ -1,7 +1,12 @@
return { return {
"echasnovski/mini.bufremove", "echasnovski/mini.bufremove",
config = function() config = function()
_G.MiniBufremove = require( 'mini.bufremove' ); _G.MiniBufremove = require("mini.bufremove")
vim.keymap.set( 'n', '<C-x>', ':lua MiniBufremove.delete()<CR>', { silent = true, noremap = true, desc = 'Remove buffer' } ); vim.keymap.set(
"n",
"<C-x>",
":lua MiniBufremove.delete()<CR>",
{ silent = true, noremap = true, desc = "Remove buffer" }
)
end, end,
} }

View File

@ -1,7 +1,7 @@
return { return {
-- open file at previous position -- open file at previous position
'ethanholz/nvim-lastplace', "ethanholz/nvim-lastplace",
config = function() config = function()
require('nvim-lastplace').setup{} require("nvim-lastplace").setup({})
end, end,
} }

View File

@ -141,6 +141,6 @@ return {
custom_hl_group = nil, -- "Visual" or any other hl group to use instead of inverted colors custom_hl_group = nil, -- "Visual" or any other hl group to use instead of inverted colors
}) })
vim.keymap.set("n", "<leader>n", ":Navbuddy<CR>", { silent = true, desc = "open navbuddy menu" }) vim.keymap.set("n", "<leader><leader>n", ":Navbuddy<CR>", { silent = true, desc = "open navbuddy menu" })
end, end,
} }

View File

@ -174,7 +174,7 @@ return {
}, },
nesting_rules = {}, nesting_rules = {},
filesystem = { filesystem = {
scan_mode = 'deep', scan_mode = "deep",
filtered_items = { filtered_items = {
visible = false, -- when true, they will just be displayed differently than normal items visible = false, -- when true, they will just be displayed differently than normal items
hide_dotfiles = true, hide_dotfiles = true,

View File

@ -35,34 +35,34 @@ return {
-- Recent Commands -- Recent Commands
opts.desc = "Show recent commands" opts.desc = "Show recent commands"
vim.keymap.set('n', '<leader>frc', ':Telescope command_history<CR>', opts) vim.keymap.set("n", "<leader>frc", ":Telescope command_history<CR>", opts)
-- Recent Searches -- Recent Searches
opts.desc = "Show recent searches" opts.desc = "Show recent searches"
vim.keymap.set('n', '<leader>frs', ':Telescope search_history<CR>', opts) vim.keymap.set("n", "<leader>frs", ":Telescope search_history<CR>", opts)
-- Old Files -- Old Files
opts.desc = "Show recent files" opts.desc = "Show recent files"
vim.keymap.set('n', '<leader>frf', ':Telescope oldfiles<CR>', opts) vim.keymap.set("n", "<leader>frf", ":Telescope oldfiles<CR>", opts)
-- Quickfix Items -- Quickfix Items
opts.desc = "Show quickfix items" opts.desc = "Show quickfix items"
vim.keymap.set('n', '<leader>fq', ':Telescope quickfix<CR>', opts) vim.keymap.set("n", "<leader>fq", ":Telescope quickfix<CR>", opts)
-- Spell Suggestions -- Spell Suggestions
opts.desc = "Show spell suggestions" opts.desc = "Show spell suggestions"
vim.keymap.set('n', '<leader>fs', ':Telescope spell_suggest<CR>', opts) vim.keymap.set("n", "<leader>fs", ":Telescope spell_suggest<CR>", opts)
-- Diagnostics -- Diagnostics
opts.desc = "Show diagnostics" opts.desc = "Show diagnostics"
vim.keymap.set('n', '<leader>fd', ':Telescope diagnostics<CR>', opts) vim.keymap.set("n", "<leader>fd", ":Telescope diagnostics<CR>", opts)
-- Notifications -- Notifications
opts.desc = "Show notifications" opts.desc = "Show notifications"
vim.keymap.set('n', '<leader>fn', ':Telescope notify<CR>', opts) vim.keymap.set("n", "<leader>fn", ":Telescope notify<CR>", opts)
-- Implementations -- Implementations
opts.desc = "Show implementations" opts.desc = "Show implementations"
vim.keymap.set('n', '<leader>fi', ':Telescope lsp_implementations<CR>', opts) vim.keymap.set("n", "<leader>fi", ":Telescope lsp_implementations<CR>", opts)
end, end,
} }

View File

@ -6,7 +6,5 @@ return {
vim.o.timeout = true vim.o.timeout = true
vim.o.timeoutlen = 500 vim.o.timeoutlen = 500
end, end,
opts = { opts = {},
}
} }

View File

@ -1,9 +1,9 @@
return { return {
-- colorizes colors in code -- colorizes colors in code
'NvChad/nvim-colorizer.lua' , "NvChad/nvim-colorizer.lua",
--cmd = 'ColorizerToggle', --cmd = 'ColorizerToggle',
config = function() config = function()
require("colorizer").setup { require("colorizer").setup({
filetypes = { "*" }, filetypes = { "*" },
user_default_options = { user_default_options = {
RGB = true, -- #RGB hex codes - #FCE RGB = true, -- #RGB hex codes - #FCE
@ -21,14 +21,14 @@ return {
-- True is same as normal -- True is same as normal
tailwind = false, -- Enable tailwind colors tailwind = false, -- Enable tailwind colors
-- parsers can contain values used in |user_default_options| -- parsers can contain values used in |user_default_options|
sass = { enable = false, parsers = { "css" }, }, -- Enable sass colors sass = { enable = false, parsers = { "css" } }, -- Enable sass colors
virtualtext = "", virtualtext = "",
-- update color values even if buffer is not focused -- update color values even if buffer is not focused
-- example use: cmp_menu, cmp_docs -- example use: cmp_menu, cmp_docs
always_update = false always_update = false,
}, },
-- all the sub-options of filetypes apply to buftypes -- all the sub-options of filetypes apply to buftypes
buftypes = {}, buftypes = {},
} })
end, end,
} }

View File

@ -13,7 +13,7 @@ return {
functions = "italic", functions = "italic",
keywords = "italic", keywords = "italic",
types = "italic", types = "italic",
} },
}, },
palettes = { palettes = {
all = { all = {
@ -77,7 +77,7 @@ return {
statement = "magenta", statement = "magenta",
string = "cyan", string = "cyan",
type = "red", type = "red",
variable = "orange" variable = "orange",
}, },
diag = { diag = {
error = "darkred", error = "darkred",
@ -91,22 +91,22 @@ return {
warn = "#a16b00", warn = "#a16b00",
info = "cyan", info = "cyan",
hint = "bg3", hint = "bg3",
ok = "green"; ok = "green",
}, },
diff = { diff = {
add = "darkgreen", add = "darkgreen",
delete = "darkred", delete = "darkred",
changed = "lightblue", changed = "lightblue",
text = "fg0" text = "fg0",
}, },
git = { git = {
add = "darkgreen", add = "darkgreen",
removed = "darkred", removed = "darkred",
changed = "lightblue", changed = "lightblue",
conflict = "orange", conflict = "orange",
ignored = "gray" ignored = "gray",
} },
} },
}, },
groups = { groups = {
all = { all = {

View File

@ -1,10 +1,10 @@
return { return {
-- add comment keybinds -- add comment keybinds
'numToStr/Comment.nvim', "numToStr/Comment.nvim",
opts = {}, opts = {},
lazy = false, lazy = false,
config = function() config = function()
require('Comment').setup() require("Comment").setup()
require('Comment.ft').set('hyprlang', '#%s') require("Comment.ft").set("hyprlang", "#%s")
end end,
} }

View File

@ -1,5 +1,5 @@
return { return {
-- prettier prompts -- prettier prompts
'stevearc/dressing.nvim', "stevearc/dressing.nvim",
event = 'VeryLazy', event = "VeryLazy",
} }

View File

@ -1,7 +1,7 @@
return { return {
-- status line -- status line
'nvim-lualine/lualine.nvim', "nvim-lualine/lualine.nvim",
dependencies = { 'nvim-tree/nvim-web-devicons' }, dependencies = { "nvim-tree/nvim-web-devicons" },
config = function() config = function()
local function getWords() local function getWords()
local wc = vim.api.nvim_eval("wordcount()") local wc = vim.api.nvim_eval("wordcount()")
@ -11,45 +11,45 @@ return {
return wc["words"] return wc["words"]
end end
end end
require('lualine').setup { require("lualine").setup({
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = "auto", theme = "auto",
component_separators = { left = '', right = ''}, component_separators = { left = "", right = "" },
section_separators = { left = '', right = ''}, section_separators = { left = "", right = "" },
disabled_filetypes = { disabled_filetypes = {
statusline = {}, statusline = {},
winbar = {}, winbar = {},
}, },
ignore_focus = { 'neo-tree' }, ignore_focus = { "neo-tree" },
always_divide_middle = true, always_divide_middle = true,
globalstatus = false, globalstatus = false,
refresh = { refresh = {
statusline = 1000, statusline = 1000,
tabline = 1000, tabline = 1000,
winbar = 1000, winbar = 1000,
} },
}, },
sections = { sections = {
lualine_a = { { 'mode', separator = { left = '', right = '' }, } }, lualine_a = { { "mode", separator = { left = "", right = "" } } },
lualine_b = {'branch', 'diff', 'diagnostics'}, lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = {'filename'}, lualine_c = { "filename" },
lualine_x = { getWords, 'encoding', 'fileformat', 'filetype'}, lualine_x = { getWords, "encoding", "fileformat", "filetype" },
lualine_y = { { 'progress', left_padding=0 } }, lualine_y = { { "progress", left_padding = 0 } },
lualine_z = { { 'location', separator = { left = '', right = '' }, padding=0} } lualine_z = { { "location", separator = { left = "", right = "" }, padding = 0 } },
}, },
inactive_sections = { inactive_sections = {
lualine_a = {}, lualine_a = {},
lualine_b = {}, lualine_b = {},
lualine_c = {'filename'}, lualine_c = { "filename" },
lualine_x = {'location'}, lualine_x = { "location" },
lualine_y = {}, lualine_y = {},
lualine_z = {} lualine_z = {},
}, },
tabline = {}, tabline = {},
winbar = {}, winbar = {},
inactive_winbar = {}, inactive_winbar = {},
extensions = {} extensions = {},
} })
end, end,
} }

View File

@ -10,12 +10,12 @@ return {
"rcarriga/nvim-notify", "rcarriga/nvim-notify",
}, },
config = function() config = function()
require( 'notify' ).setup( { require("notify").setup({
max_width = 80, max_width = 80,
minimum_width = 30, minimum_width = 30,
render = 'wrapped-default', -- default, minimal, simple, compact, wrapped-compact or wrapped-default render = "wrapped-default", -- default, minimal, simple, compact, wrapped-compact or wrapped-default
stages = 'slide', -- fade_in_slide_out, fade, slide, static stages = "slide", -- fade_in_slide_out, fade, slide, static
} ); })
require("noice").setup({ require("noice").setup({
lsp = { lsp = {
-- override markdown rendering so that **cmp** and other plugins use **Treesitter** -- override markdown rendering so that **cmp** and other plugins use **Treesitter**

View File

@ -26,7 +26,7 @@ return {
[[ ]], [[ ]],
}, },
highlight = "String", highlight = "String",
default_color = "#010155" default_color = "#010155",
}, },
quotes = { quotes = {
@ -43,7 +43,7 @@ return {
end end
end, end,
highlight = "String", highlight = "String",
default_color = "#FFFFFF" default_color = "#FFFFFF",
}, },
old = { old = {
@ -58,12 +58,12 @@ return {
}, },
options = { options = {
mapping_keys = false; mapping_keys = false,
}, },
colors = { colors = {
background = "#000000", background = "#000000",
folded_section = "#100000" folded_section = "#100000",
}, },
mappings = { mappings = {
@ -71,7 +71,7 @@ return {
open_file = "<CR>", open_file = "<CR>",
}, },
parts = {"title", "quotes", "old"} parts = { "title", "quotes", "old" },
}) })
end, end,
} }

View File

@ -48,9 +48,15 @@ return {
end end
vim.fn.sign_define("DapBreakpoint", { text = "", texthl = "DapBreakpoint", linehl = "", numhl = "" }) vim.fn.sign_define("DapBreakpoint", { text = "", texthl = "DapBreakpoint", linehl = "", numhl = "" })
vim.fn.sign_define("DapBreakpointCondition", { text = "", texthl = "DapBreakpointCondition", linehl = "", numhl = ""}) vim.fn.sign_define(
"DapBreakpointCondition",
{ text = "", texthl = "DapBreakpointCondition", linehl = "", numhl = "" }
)
vim.fn.sign_define("DapLogPoint", { text = "", texthl = "DapLogPoint", linehl = "", numhl = "" }) vim.fn.sign_define("DapLogPoint", { text = "", texthl = "DapLogPoint", linehl = "", numhl = "" })
vim.fn.sign_define('DapStopped', { text='', texthl='DapStopped', linehl='DapStopped', numhl= 'DapStopped' }) vim.fn.sign_define(
"DapStopped",
{ text = "", texthl = "DapStopped", linehl = "DapStopped", numhl = "DapStopped" }
)
dap.configurations.python = { dap.configurations.python = {
{ {
@ -91,7 +97,7 @@ return {
else else
cb({ cb({
type = "executable", type = "executable",
command = vim.fn.stdpath("data") .. '/mason/packages/debugpy/venv/bin/python', command = vim.fn.stdpath("data") .. "/mason/packages/debugpy/venv/bin/python",
args = { "-m", "debugpy.adapter" }, args = { "-m", "debugpy.adapter" },
options = { options = {
source_filetype = "python", source_filetype = "python",

View File

@ -1,13 +1,13 @@
return { return {
"windwp/nvim-ts-autotag", "windwp/nvim-ts-autotag",
config = function() config = function()
require('nvim-ts-autotag').setup({ require("nvim-ts-autotag").setup({
opts = { opts = {
-- Defaults -- Defaults
enable_close = true, -- Auto close tags enable_close = true, -- Auto close tags
enable_rename = true, -- Auto rename pairs of tags enable_rename = true, -- Auto rename pairs of tags
enable_close_on_slash = true -- Auto close on trailing </ enable_close_on_slash = true, -- Auto close on trailing </
}, },
}) })
end end,
} }

View File

@ -1,16 +1,21 @@
return { return {
'uga-rosa/ccc.nvim', "uga-rosa/ccc.nvim",
config = function() config = function()
local ccc = require( 'ccc' ); local ccc = require("ccc")
vim.opt.termguicolors = true; vim.opt.termguicolors = true
ccc.setup({ ccc.setup({
highlighter = { highlighter = {
auto_enable = false, auto_enable = false,
lsp = true lsp = true,
} },
}) })
local keymap = vim.keymap local keymap = vim.keymap
keymap.set( 'n', '<leader>cp', '<cmd>CccPick<CR>', { noremap = true, silent = true, desc = "Toggle colour picker" } ) keymap.set(
end "n",
"<leader>cp",
"<cmd>CccPick<CR>",
{ noremap = true, silent = true, desc = "Toggle colour picker" }
)
end,
} }

View File

@ -6,9 +6,8 @@ return {
notification = { notification = {
window = { window = {
winblend = 0, winblend = 0,
} },
} },
}) })
end end,
} }

View File

@ -1,9 +1,9 @@
return { return {
-- indent lines -- indent lines
'lukas-reineke/indent-blankline.nvim', "lukas-reineke/indent-blankline.nvim",
opts = {}, opts = {},
main = 'ibl', main = "ibl",
config = function() config = function()
require('ibl').setup() require("ibl").setup()
end end,
} }

View File

@ -4,14 +4,16 @@ return {
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" }, cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
ft = { "markdown" }, ft = { "markdown" },
build = function(plugin) build = function(plugin)
if vim.fn.executable "npx" then if vim.fn.executable("npx") then
vim.cmd("!cd " .. plugin.dir .. " && cd app && npx --yes yarn install") vim.cmd("!cd " .. plugin.dir .. " && cd app && npx --yes yarn install")
else else
vim.cmd [[Lazy load markdown-preview.nvim]] vim.cmd([[Lazy load markdown-preview.nvim]])
vim.fn["mkdp#util#install"]() vim.fn["mkdp#util#install"]()
end end
end, end,
init = function() init = function()
if vim.fn.executable "npx" then vim.g.mkdp_filetypes = { "markdown" } end if vim.fn.executable("npx") then
vim.g.mkdp_filetypes = { "markdown" }
end
end, end,
} }

View File

@ -2,16 +2,16 @@ return {
"smoka7/multicursors.nvim", "smoka7/multicursors.nvim",
event = "VeryLazy", event = "VeryLazy",
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>', "<cmd>MCstart<cr>",
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

@ -3,8 +3,8 @@ return {
config = function() config = function()
local opts = { noremap = true, silent = true, desc = "Generate docs" } local opts = { noremap = true, silent = true, desc = "Generate docs" }
vim.api.nvim_set_keymap("n", "<leader>gd", ":lua require('neogen').generate()<CR>", opts) vim.api.nvim_set_keymap("n", "<leader>gd", ":lua require('neogen').generate()<CR>", opts)
require( 'neogen' ).setup( { require("neogen").setup({
snippet_engine = "luasnip" snippet_engine = "luasnip",
} ); })
end end,
} }

View File

@ -4,5 +4,5 @@ return {
event = "VeryLazy", event = "VeryLazy",
config = function() config = function()
require("nvim-surround").setup() require("nvim-surround").setup()
end end,
} }

View File

@ -24,30 +24,33 @@ M.sudo_exec = function(cmd, print_output)
print(out) print(out)
return false return false
end end
if print_output then print("\r\n", out) end if print_output then
print("\r\n", out)
end
return true return true
end end
M.sudo_write = function(tmpfile, filepath) M.sudo_write = function(tmpfile, filepath)
if not tmpfile then tmpfile = vim.fn.tempname() end if not tmpfile then
if not filepath then filepath = vim.fn.expand("%") end tmpfile = vim.fn.tempname()
end
if not filepath then
filepath = vim.fn.expand("%")
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", local cmd = string.format("dd if=%s of=%s bs=1048576", vim.fn.shellescape(tmpfile), vim.fn.shellescape(filepath))
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( vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", true)
"<Esc>", true, false, true), "n", true)
end end
vim.fn.delete(tmpfile) vim.fn.delete(tmpfile)
end end