diff --git a/neovim/.config/nvim/after/plugin/autocmds.lua b/neovim/.config/nvim/after/plugin/autocmds.lua index 8d6c9b6..cc4244d 100644 --- a/neovim/.config/nvim/after/plugin/autocmds.lua +++ b/neovim/.config/nvim/after/plugin/autocmds.lua @@ -7,15 +7,3 @@ vim.api.nvim_create_autocmd("TextYankPost", { vim.highlight.on_yank({ timeout = 200 }) 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, -}) diff --git a/neovim/.config/nvim/after/plugin/autopairs.lua b/neovim/.config/nvim/after/plugin/autopairs.lua new file mode 100644 index 0000000..7faf5be --- /dev/null +++ b/neovim/.config/nvim/after/plugin/autopairs.lua @@ -0,0 +1 @@ +require("nvim-autopairs").setup({}) diff --git a/neovim/.config/nvim/after/plugin/comment.lua b/neovim/.config/nvim/after/plugin/commentstring.lua similarity index 93% rename from neovim/.config/nvim/after/plugin/comment.lua rename to neovim/.config/nvim/after/plugin/commentstring.lua index d6433ad..971d58c 100644 --- a/neovim/.config/nvim/after/plugin/comment.lua +++ b/neovim/.config/nvim/after/plugin/commentstring.lua @@ -1,3 +1,5 @@ +require("Comment").setup({}) +require("ts_context_commentstring").setup({}) local U = require("Comment.utils") local ctype_to_commentstring = { diff --git a/neovim/.config/nvim/after/plugin/comp.lua b/neovim/.config/nvim/after/plugin/comp.lua index ee4b9db..f7f8b8a 100644 --- a/neovim/.config/nvim/after/plugin/comp.lua +++ b/neovim/.config/nvim/after/plugin/comp.lua @@ -10,6 +10,9 @@ cmp.setup({ end, }, mapping = { + [""] = cmp.mapping(function(fallback) + fallback() + end), [""] = cmp.mapping(function(fallback) if ls.jumpable(1) then ls.jump(1) @@ -121,92 +124,3 @@ cmp.setup.filetype("gitcommit", { }) 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 = "<>", - } - ) - ), -}) diff --git a/neovim/.config/nvim/after/plugin/formatting.lua b/neovim/.config/nvim/after/plugin/formatting.lua deleted file mode 100644 index f5b80d9..0000000 --- a/neovim/.config/nvim/after/plugin/formatting.lua +++ /dev/null @@ -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, {}) diff --git a/neovim/.config/nvim/after/plugin/git.lua b/neovim/.config/nvim/after/plugin/git.lua index 32a6fff..52aafd2 100644 --- a/neovim/.config/nvim/after/plugin/git.lua +++ b/neovim/.config/nvim/after/plugin/git.lua @@ -28,3 +28,5 @@ vim.keymap.set("n", "gb", function() show_remote_tracking_branches = false, }) end) + +vim.api.nvim_set_hl(0, "GitSignsCurrentLineBlame", { fg = "#888888" }) diff --git a/neovim/.config/nvim/after/plugin/lsp/config.lua b/neovim/.config/nvim/after/plugin/lsp/config.lua index 3a161d4..9729551 100644 --- a/neovim/.config/nvim/after/plugin/lsp/config.lua +++ b/neovim/.config/nvim/after/plugin/lsp/config.lua @@ -1,6 +1,5 @@ local ts = require("telescope.builtin") 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()) capabilities.textDocument.completion.completionItem.snippetSupport = true @@ -25,10 +24,6 @@ null_ls.setup({ pattern = "*", group = group, callback = function() - if not formatting.is_enabled() then - return - end - vim.lsp.buf.format({ filter = function(client) return not vim.tbl_contains(servers_with_annoying_formatters, client.name) diff --git a/neovim/.config/nvim/after/plugin/lsp/webdev.lua b/neovim/.config/nvim/after/plugin/lsp/webdev.lua index ebbf1eb..c2f38e4 100644 --- a/neovim/.config/nvim/after/plugin/lsp/webdev.lua +++ b/neovim/.config/nvim/after/plugin/lsp/webdev.lua @@ -118,7 +118,7 @@ vim.lsp.config.emmet_ls = { "typescript", "typescript.tsx", "typescriptreact", - "svelte" + "svelte", }, root_markers = { "package.json", ".git", vim.uv.cwd() }, } diff --git a/neovim/.config/nvim/after/plugin/nvim-tree.lua b/neovim/.config/nvim/after/plugin/nvim-tree.lua index 393b434..44f9e5c 100644 --- a/neovim/.config/nvim/after/plugin/nvim-tree.lua +++ b/neovim/.config/nvim/after/plugin/nvim-tree.lua @@ -34,10 +34,11 @@ local function on_attach(bufnr) end require("nvim-tree").setup({ + on_attach = on_attach, disable_netrw = true, hijack_netrw = true, hijack_cursor = true, - open_on_tab = false, + open_on_tab = true, update_cwd = true, auto_reload_on_write = true, reload_on_bufenter = true, @@ -97,7 +98,6 @@ require("nvim-tree").setup({ show_on_dirs = true, icons = { hint = "", info = "", warning = "", error = "๏—" }, }, - on_attach = on_attach, }) vim.keymap.set("n", "", vim.cmd.NvimTreeToggle) diff --git a/neovim/.config/nvim/after/plugin/options.lua b/neovim/.config/nvim/after/plugin/options.lua index 920ad24..0d16675 100644 --- a/neovim/.config/nvim/after/plugin/options.lua +++ b/neovim/.config/nvim/after/plugin/options.lua @@ -41,5 +41,3 @@ vim.opt.listchars = { multispace = "ยท", tab = ">~", leadmultispace = "โ”Š " } vim.opt.spelllang = "en_us,ru" vim.cmd.colorscheme("retrobox") - -vim.api.nvim_set_hl(0, "GitSignsCurrentLineBlame", { fg = "#888888" }) diff --git a/neovim/.config/nvim/after/plugin/remaps.lua b/neovim/.config/nvim/after/plugin/remaps.lua index da76c34..43d92e0 100644 --- a/neovim/.config/nvim/after/plugin/remaps.lua +++ b/neovim/.config/nvim/after/plugin/remaps.lua @@ -16,5 +16,3 @@ vim.keymap.set("n", "tn", ":tabnew") vim.keymap.set("n", "tN", ":-tabnew") vim.keymap.set("n", "H", ":tabprev") vim.keymap.set("n", "L", ":tabnext") - -vim.keymap.set("n", "gl", require("daniil.gitblame").open_blame_window) diff --git a/neovim/.config/nvim/init.lua b/neovim/.config/nvim/init.lua index 35753c9..8ea8915 100644 --- a/neovim/.config/nvim/init.lua +++ b/neovim/.config/nvim/init.lua @@ -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.opt.termguicolors = true -require("lazy").setup({ - spec = { - { "nvim-lua/plenary.nvim" }, +local pack = require("pack") - { "nvim-treesitter/nvim-treesitter" }, - { "nvim-treesitter/playground" }, +pack.add("kyazdani42/nvim-web-devicons") +pack.add("nvim-lua/plenary.nvim") - { - "JoosepAlviste/nvim-ts-context-commentstring", - config = function() - require("ts_context_commentstring").setup({}) - vim.g.skip_ts_context_commentstring_module = true - end, - }, +pack.add("nvim-tree/nvim-tree.lua") - { "nvim-telescope/telescope.nvim" }, +pack.add("nvim-lualine/lualine.nvim") - { "tpope/vim-fugitive" }, - { "lewis6991/gitsigns.nvim" }, +pack.add("nvim-telescope/telescope.nvim") - { - "hrsh7th/nvim-cmp", - dependencies = { - { "hrsh7th/cmp-nvim-lsp" }, - { "hrsh7th/cmp-buffer" }, - { "hrsh7th/cmp-path" }, - { "hrsh7th/cmp-cmdline" }, - { "petertriho/cmp-git" }, - }, - }, +pack.add({ + src = "nvim-treesitter/nvim-treesitter", + version = "master", +}) +pack.add("windwp/nvim-ts-autotag") +pack.add("windwp/nvim-autopairs") - { - "L3MON4D3/LuaSnip", - dependencies = { - "saadparwaiz1/cmp_luasnip", - "rafamadriz/friendly-snippets", - }, - }, +pack.add("tpope/vim-fugitive") +pack.add("lewis6991/gitsigns.nvim") - { "nvimtools/none-ls.nvim", dependencies = { - "nvimtools/none-ls-extras.nvim", - } }, +pack.add("numToStr/Comment.nvim") +pack.add("JoosepAlviste/nvim-ts-context-commentstring") - { - "kyazdani42/nvim-tree.lua", - dependencies = { - { "kyazdani42/nvim-web-devicons" }, - }, - }, +pack.add("b0o/SchemaStore.nvim") - { - "stevearc/oil.nvim", - config = function() - require("oil").setup({ - default_file_explorer = false, - }) - end, - }, - - { "windwp/nvim-autopairs", opts = {} }, - { "windwp/nvim-ts-autotag" }, - - { "numToStr/Comment.nvim" }, - - { "nvim-lualine/lualine.nvim" }, - - { "b0o/SchemaStore.nvim" }, +pack.add({ + src = "L3MON4D3/LuaSnip", + deps = { + "saadparwaiz1/cmp_luasnip", + "rafamadriz/friendly-snippets", }, }) + +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, {}) diff --git a/neovim/.config/nvim/lua/daniil/formatting/init.lua b/neovim/.config/nvim/lua/daniil/formatting/init.lua deleted file mode 100644 index 24fb168..0000000 --- a/neovim/.config/nvim/lua/daniil/formatting/init.lua +++ /dev/null @@ -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 diff --git a/neovim/.config/nvim/lua/daniil/gitblame.lua b/neovim/.config/nvim/lua/daniil/gitblame.lua deleted file mode 100644 index c812dd5..0000000 --- a/neovim/.config/nvim/lua/daniil/gitblame.lua +++ /dev/null @@ -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", "", ":q", { buffer = bufnr }) - vim.keymap.set("n", "q", ":q", { buffer = bufnr }) - - -- TODO: open not at the top of the buffer, but on line in OG file -end - -return M diff --git a/neovim/.config/nvim/lua/daniil/utils.lua b/neovim/.config/nvim/lua/daniil/utils.lua deleted file mode 100644 index fc14b66..0000000 --- a/neovim/.config/nvim/lua/daniil/utils.lua +++ /dev/null @@ -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 diff --git a/neovim/.config/nvim/lua/pack.lua b/neovim/.config/nvim/lua/pack.lua new file mode 100644 index 0000000..ef40267 --- /dev/null +++ b/neovim/.config/nvim/lua/pack.lua @@ -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 diff --git a/neovim/.config/nvim/nvim-pack-lock.json b/neovim/.config/nvim/nvim-pack-lock.json new file mode 100644 index 0000000..bf2ab3c --- /dev/null +++ b/neovim/.config/nvim/nvim-pack-lock.json @@ -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" + } + } +} \ No newline at end of file