neovim: move to vim.pack from lazy

This commit is contained in:
2026-03-13 19:18:43 +03:00
parent 8883f27fb9
commit 33c988cfb1
17 changed files with 224 additions and 320 deletions

View File

@@ -7,15 +7,3 @@ vim.api.nvim_create_autocmd("TextYankPost", {
vim.highlight.on_yank({ timeout = 200 }) vim.highlight.on_yank({ timeout = 200 })
end, end,
}) })
vim.api.nvim_create_autocmd("BufEnter", {
pattern = "*",
group = group,
callback = function()
local lead = ""
for _ = 1, vim.bo.shiftwidth - 1 do
lead = lead .. " "
end
vim.opt_local.listchars:append({ leadmultispace = lead })
end,
})

View File

@@ -0,0 +1 @@
require("nvim-autopairs").setup({})

View File

@@ -1,3 +1,5 @@
require("Comment").setup({})
require("ts_context_commentstring").setup({})
local U = require("Comment.utils") local U = require("Comment.utils")
local ctype_to_commentstring = { local ctype_to_commentstring = {

View File

@@ -10,6 +10,9 @@ cmp.setup({
end, end,
}, },
mapping = { mapping = {
["<CR>"] = cmp.mapping(function(fallback)
fallback()
end),
["<C-u>"] = cmp.mapping(function(fallback) ["<C-u>"] = cmp.mapping(function(fallback)
if ls.jumpable(1) then if ls.jumpable(1) then
ls.jump(1) ls.jump(1)
@@ -121,92 +124,3 @@ cmp.setup.filetype("gitcommit", {
}) })
require("luasnip.loaders.from_vscode").lazy_load() require("luasnip.loaders.from_vscode").lazy_load()
local s = ls.snippet
local i = ls.insert_node
local t = ls.text_node
local d = ls.dynamic_node
local sn = ls.snippet_node
local fmt = require("luasnip.extras.fmt").fmt
local ts_utils = require("nvim-treesitter.ts_utils")
ls.add_snippets("go", {
s(
"iferr",
fmt(
[[
if err != nil {
<>
}
]],
{
d(1, function()
local current_node = ts_utils.get_node_at_cursor(0, true)
if not current_node then
return ""
end
local func = current_node
while func do
if func:type() == "function_declaration" then
break
end
func = func:parent()
end
if not func then
return ""
end
local return_type_node = func:child(3)
if not return_type_node then
return ""
end
local params = {}
for index = 0, return_type_node:child_count(), 1 do
local param = return_type_node:child(index)
if param and param:type() == "parameter_declaration" then
local text = ts_utils.get_node_text(param)
table.insert(params, text[1])
end
end
local rec = {
["string"] = '""',
["int"] = "0",
["uint"] = "0",
["error"] = "err",
["bool"] = "false",
}
local size = vim.tbl_count(params)
if size == 0 then
return sn(nil, { i(1) })
end
local x = { t("return ") }
for index, param in ipairs(params) do
local replace = rec[param]
if replace ~= nil then
table.insert(x, i(index, replace))
else
table.insert(x, i(index, param))
end
if index < size then
table.insert(x, t(", "))
end
end
return sn(nil, x)
end, {}),
},
{
delimiters = "<>",
}
)
),
})

View File

@@ -1,6 +0,0 @@
local formatting = require("daniil.formatting")
vim.api.nvim_create_user_command("FormattingEnable", formatting.enable, {})
vim.api.nvim_create_user_command("FormattingDisable", formatting.disable, {})
vim.api.nvim_create_user_command("FormattingToggle", formatting.toggle, {})
vim.api.nvim_create_user_command("FormattingStatus", formatting.status, {})

View File

@@ -28,3 +28,5 @@ vim.keymap.set("n", "<leader>gb", function()
show_remote_tracking_branches = false, show_remote_tracking_branches = false,
}) })
end) end)
vim.api.nvim_set_hl(0, "GitSignsCurrentLineBlame", { fg = "#888888" })

View File

@@ -1,6 +1,5 @@
local ts = require("telescope.builtin") local ts = require("telescope.builtin")
local null_ls = require("null-ls") local null_ls = require("null-ls")
local formatting = require("daniil.formatting")
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.snippetSupport = true
@@ -25,10 +24,6 @@ null_ls.setup({
pattern = "*", pattern = "*",
group = group, group = group,
callback = function() callback = function()
if not formatting.is_enabled() then
return
end
vim.lsp.buf.format({ vim.lsp.buf.format({
filter = function(client) filter = function(client)
return not vim.tbl_contains(servers_with_annoying_formatters, client.name) return not vim.tbl_contains(servers_with_annoying_formatters, client.name)

View File

@@ -118,7 +118,7 @@ vim.lsp.config.emmet_ls = {
"typescript", "typescript",
"typescript.tsx", "typescript.tsx",
"typescriptreact", "typescriptreact",
"svelte" "svelte",
}, },
root_markers = { "package.json", ".git", vim.uv.cwd() }, root_markers = { "package.json", ".git", vim.uv.cwd() },
} }

View File

@@ -34,10 +34,11 @@ local function on_attach(bufnr)
end end
require("nvim-tree").setup({ require("nvim-tree").setup({
on_attach = on_attach,
disable_netrw = true, disable_netrw = true,
hijack_netrw = true, hijack_netrw = true,
hijack_cursor = true, hijack_cursor = true,
open_on_tab = false, open_on_tab = true,
update_cwd = true, update_cwd = true,
auto_reload_on_write = true, auto_reload_on_write = true,
reload_on_bufenter = true, reload_on_bufenter = true,
@@ -97,7 +98,6 @@ require("nvim-tree").setup({
show_on_dirs = true, show_on_dirs = true,
icons = { hint = "", info = "", warning = "", error = "" }, icons = { hint = "", info = "", warning = "", error = "" },
}, },
on_attach = on_attach,
}) })
vim.keymap.set("n", "<leader><leader>", vim.cmd.NvimTreeToggle) vim.keymap.set("n", "<leader><leader>", vim.cmd.NvimTreeToggle)

View File

@@ -41,5 +41,3 @@ vim.opt.listchars = { multispace = "·", tab = ">~", leadmultispace = "┊ " }
vim.opt.spelllang = "en_us,ru" vim.opt.spelllang = "en_us,ru"
vim.cmd.colorscheme("retrobox") vim.cmd.colorscheme("retrobox")
vim.api.nvim_set_hl(0, "GitSignsCurrentLineBlame", { fg = "#888888" })

View File

@@ -16,5 +16,3 @@ vim.keymap.set("n", "tn", ":tabnew<CR>")
vim.keymap.set("n", "tN", ":-tabnew<CR>") vim.keymap.set("n", "tN", ":-tabnew<CR>")
vim.keymap.set("n", "H", ":tabprev<CR>") vim.keymap.set("n", "H", ":tabprev<CR>")
vim.keymap.set("n", "L", ":tabnext<CR>") vim.keymap.set("n", "L", ":tabnext<CR>")
vim.keymap.set("n", "<leader>gl", require("daniil.gitblame").open_blame_window)

View File

@@ -1,89 +1,79 @@
-- Install lazy automagically
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = " " vim.g.mapleader = " "
vim.opt.termguicolors = true vim.opt.termguicolors = true
require("lazy").setup({ local pack = require("pack")
spec = {
{ "nvim-lua/plenary.nvim" },
{ "nvim-treesitter/nvim-treesitter" }, pack.add("kyazdani42/nvim-web-devicons")
{ "nvim-treesitter/playground" }, pack.add("nvim-lua/plenary.nvim")
{ pack.add("nvim-tree/nvim-tree.lua")
"JoosepAlviste/nvim-ts-context-commentstring",
config = function()
require("ts_context_commentstring").setup({})
vim.g.skip_ts_context_commentstring_module = true
end,
},
{ "nvim-telescope/telescope.nvim" }, pack.add("nvim-lualine/lualine.nvim")
{ "tpope/vim-fugitive" }, pack.add("nvim-telescope/telescope.nvim")
{ "lewis6991/gitsigns.nvim" },
{ pack.add({
"hrsh7th/nvim-cmp", src = "nvim-treesitter/nvim-treesitter",
dependencies = { version = "master",
{ "hrsh7th/cmp-nvim-lsp" }, })
{ "hrsh7th/cmp-buffer" }, pack.add("windwp/nvim-ts-autotag")
{ "hrsh7th/cmp-path" }, pack.add("windwp/nvim-autopairs")
{ "hrsh7th/cmp-cmdline" },
{ "petertriho/cmp-git" },
},
},
{ pack.add("tpope/vim-fugitive")
"L3MON4D3/LuaSnip", pack.add("lewis6991/gitsigns.nvim")
dependencies = {
"saadparwaiz1/cmp_luasnip",
"rafamadriz/friendly-snippets",
},
},
{ "nvimtools/none-ls.nvim", dependencies = { pack.add("numToStr/Comment.nvim")
"nvimtools/none-ls-extras.nvim", pack.add("JoosepAlviste/nvim-ts-context-commentstring")
} },
{ pack.add("b0o/SchemaStore.nvim")
"kyazdani42/nvim-tree.lua",
dependencies = {
{ "kyazdani42/nvim-web-devicons" },
},
},
{ pack.add({
"stevearc/oil.nvim", src = "L3MON4D3/LuaSnip",
config = function() deps = {
require("oil").setup({ "saadparwaiz1/cmp_luasnip",
default_file_explorer = false, "rafamadriz/friendly-snippets",
})
end,
},
{ "windwp/nvim-autopairs", opts = {} },
{ "windwp/nvim-ts-autotag" },
{ "numToStr/Comment.nvim" },
{ "nvim-lualine/lualine.nvim" },
{ "b0o/SchemaStore.nvim" },
}, },
}) })
pack.add({
src = "hrsh7th/nvim-cmp",
deps = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"petertriho/cmp-git",
},
})
pack.add({
src = "nvimtools/none-ls.nvim",
deps = {
"nvimtools/none-ls-extras.nvim",
},
})
vim.api.nvim_create_user_command("PackUpdate", function()
vim.pack.update()
end, {})
vim.api.nvim_create_user_command("PackClean", function()
local plugins = vim.pack.get()
local items = {}
for _, plug in ipairs(plugins) do
if not plug.active then
table.insert(items, plug.spec.name)
end
end
if #items == 0 then
return
end
vim.pack.del(items)
local msg = "Deleted " .. #items .. " plugins"
vim.notify(msg)
end, {})

View File

@@ -1,35 +0,0 @@
local M = {}
vim.g.daniil_formatting_enabled = 1
function M.enable()
vim.g.daniil_formatting_enabled = 1
end
function M.disable()
vim.g.daniil_formatting_enabled = 0
end
function M.toggle()
if M.is_enabled() then
M.disable()
else
M.enable()
end
M.status()
end
function M.is_enabled()
return vim.g.daniil_formatting_enabled == 1
end
function M.status()
if M.is_enabled() then
vim.notify("Formatting enabled")
else
vim.notify("Formatting disabled")
end
end
return M

View File

@@ -1,48 +0,0 @@
local u = require("daniil.utils")
local M = {}
---@param line number
---@param path string
---@return string
local function get_commit_hash_at_line(line, path)
local cmd = vim.system({ "git", "blame", "-L", line .. "," .. line, "-p", "--", path }, { text = true }):wait()
local lines = {}
for s in cmd.stdout:gmatch("[^\r\n]+") do
table.insert(lines, s)
end
local commit_hash = lines[1]:gmatch("[^%s]+")() -- why I need to call this here but not above. i don't understand
return commit_hash
end
---@param hash string
---@param dir string
---@return string
local function get_commit_info(hash, dir)
local cmd = vim.system({ "git", "-C", dir, "show", hash }, { text = true }):wait()
return cmd.stdout
end
function M.open_blame_window()
local cursor = vim.api.nvim_win_get_cursor(0)
local line = cursor[1]
local buf_name = vim.fn.expand("%:.")
local commit_hash = get_commit_hash_at_line(line, buf_name)
local commit_info = get_commit_info(commit_hash, vim.uv.cwd())
local bufnr, winnr = u.create_floating_window_in_center(0.75, 0.75)
u.set_buffer_text(bufnr, commit_info)
vim.bo[bufnr].filetype = "gitcommit"
vim.wo[winnr].wrap = false
vim.keymap.set("n", "<esc>", ":q<CR>", { buffer = bufnr })
vim.keymap.set("n", "q", ":q<CR>", { buffer = bufnr })
-- TODO: open not at the top of the buffer, but on line in OG file
end
return M

View File

@@ -1,43 +0,0 @@
local M = {}
---@return number width, number height
function M.get_terminal_size()
local width = vim.o.columns
local height = vim.o.lines
return width, height
end
---@param width number width in percentage of screen width (0.75, 0.5, etc)
---@param height number height in percentage of screen height (0.75, 0.5, etc)
---@return number buffer, number window
function M.create_floating_window_in_center(width, height)
local bufnr = vim.api.nvim_create_buf(false, true) -- not listed, scratch buffer
local max_width, max_height = M.get_terminal_size()
local win_width = math.floor(max_width * width)
local win_height = math.floor(max_height * height)
local winnr = vim.api.nvim_open_win(bufnr, true, {
relative = "editor",
width = win_width,
height = win_height,
row = (max_height - win_height) / 2,
col = (max_width - win_width) / 2,
focusable = true,
style = "minimal",
})
return bufnr, winnr
end
---@param bufnr number
---@param content string
function M.set_buffer_text(bufnr, content)
local lines = {}
for s in content:gmatch("[^\r\n]+") do
table.insert(lines, s)
end
vim.api.nvim_buf_set_lines(bufnr, 0, vim.tbl_count(lines), false, lines)
end
return M

View File

@@ -0,0 +1,47 @@
local M = {}
---@param name string
---@return string
local function transform_plugin_name(name)
if string.sub(name, 1, 6) ~= "https:" then
name = "https://github.com/" .. name
end
return name
end
---@class Plugin
---@field src string
---@field version? string
---@field name? string
---@field deps? Plugin[] | string[]
---@param opts Plugin | string
function M.add(opts)
if type(opts) == "string" then
opts = {
src = opts,
}
end
opts.src = transform_plugin_name(opts.src)
local items = { opts }
if opts.deps and #opts.deps > 0 then
for _, dep in ipairs(opts.deps) do
if type(dep) == "string" then
table.insert(items, {
src = transform_plugin_name(dep),
})
else
dep.src = transform_plugin_name(dep.src)
table.insert(items, dep)
end
end
end
vim.pack.add(items)
end
return M

View File

@@ -0,0 +1,101 @@
{
"plugins": {
"Comment.nvim": {
"rev": "e30b7f2008e52442154b66f7c519bfd2f1e32acb",
"src": "https://github.com/numToStr/Comment.nvim"
},
"LuaSnip": {
"rev": "dae4f5aaa3574bd0c2b9dd20fb9542a02c10471c",
"src": "https://github.com/L3MON4D3/LuaSnip"
},
"SchemaStore.nvim": {
"rev": "27f7d753990c8d79bdefe75be0094e7e86eabf16",
"src": "https://github.com/b0o/SchemaStore.nvim"
},
"cmp-buffer": {
"rev": "b74fab3656eea9de20a9b8116afa3cfc4ec09657",
"src": "https://github.com/hrsh7th/cmp-buffer"
},
"cmp-cmdline": {
"rev": "d126061b624e0af6c3a556428712dd4d4194ec6d",
"src": "https://github.com/hrsh7th/cmp-cmdline"
},
"cmp-git": {
"rev": "b24309c386c9666c549a1abaedd4956541676d06",
"src": "https://github.com/petertriho/cmp-git"
},
"cmp-nvim-lsp": {
"rev": "cbc7b02bb99fae35cb42f514762b89b5126651ef",
"src": "https://github.com/hrsh7th/cmp-nvim-lsp"
},
"cmp-path": {
"rev": "c642487086dbd9a93160e1679a1327be111cbc25",
"src": "https://github.com/hrsh7th/cmp-path"
},
"cmp_luasnip": {
"rev": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90",
"src": "https://github.com/saadparwaiz1/cmp_luasnip"
},
"friendly-snippets": {
"rev": "6cd7280adead7f586db6fccbd15d2cac7e2188b9",
"src": "https://github.com/rafamadriz/friendly-snippets"
},
"gitsigns.nvim": {
"rev": "7c4faa3540d0781a28588cafbd4dd187a28ac6e3",
"src": "https://github.com/lewis6991/gitsigns.nvim"
},
"lualine.nvim": {
"rev": "47f91c416daef12db467145e16bed5bbfe00add8",
"src": "https://github.com/nvim-lualine/lualine.nvim"
},
"none-ls-extras.nvim": {
"rev": "c6fa39ac52814182c05552cb5d3750cae23ff0f0",
"src": "https://github.com/nvimtools/none-ls-extras.nvim"
},
"none-ls.nvim": {
"rev": "c9317c2a8629d4e39e7cf47be74cb67f3ab37cda",
"src": "https://github.com/nvimtools/none-ls.nvim"
},
"nvim-autopairs": {
"rev": "59bce2eef357189c3305e25bc6dd2d138c1683f5",
"src": "https://github.com/windwp/nvim-autopairs"
},
"nvim-cmp": {
"rev": "da88697d7f45d16852c6b2769dc52387d1ddc45f",
"src": "https://github.com/hrsh7th/nvim-cmp"
},
"nvim-tree.lua": {
"rev": "9197f3ee3f0c9a754aab5b16500db6d7da5f68fd",
"src": "https://github.com/nvim-tree/nvim-tree.lua"
},
"nvim-treesitter": {
"rev": "42fc28ba918343ebfd5565147a42a26580579482",
"src": "https://github.com/nvim-treesitter/nvim-treesitter",
"version": "'master'"
},
"nvim-ts-autotag": {
"rev": "8e1c0a389f20bf7f5b0dd0e00306c1247bda2595",
"src": "https://github.com/windwp/nvim-ts-autotag"
},
"nvim-ts-context-commentstring": {
"rev": "1b212c2eee76d787bbea6aa5e92a2b534e7b4f8f",
"src": "https://github.com/JoosepAlviste/nvim-ts-context-commentstring"
},
"nvim-web-devicons": {
"rev": "d7462543c9e366c0d196c7f67a945eaaf5d99414",
"src": "https://github.com/kyazdani42/nvim-web-devicons"
},
"plenary.nvim": {
"rev": "b9fd5226c2f76c951fc8ed5923d85e4de065e509",
"src": "https://github.com/nvim-lua/plenary.nvim"
},
"telescope.nvim": {
"rev": "5255aa27c422de944791318024167ad5d40aad20",
"src": "https://github.com/nvim-telescope/telescope.nvim"
},
"vim-fugitive": {
"rev": "3b753cf8c6a4dcde6edee8827d464ba9b8c4a6f0",
"src": "https://github.com/tpope/vim-fugitive"
}
}
}