From 264319500b964b8c48f49fc63a6a7f1170842530 Mon Sep 17 00:00:00 2001 From: asif Date: Mon, 26 May 2025 01:49:43 +0530 Subject: [PATCH] added autopairs, comment, cursor animation, indentation, smooth scrolling, surround and other plugins for neovim --- .luarc.json | 8 ++ nvim/.config/nvim/.luarc.json | 4 + nvim/.config/nvim/after/plugin/autopairs.lua | 20 +++++ nvim/.config/nvim/after/plugin/comment.lua | 16 ++++ nvim/.config/nvim/after/plugin/cursor.lua | 0 nvim/.config/nvim/after/plugin/indent.lua | 24 ++++++ nvim/.config/nvim/after/plugin/neoscroll.lua | 11 +++ nvim/.config/nvim/after/plugin/surround.lua | 14 ++++ nvim/.config/nvim/lua/plugins/init.lua | 77 +++++++------------- nvim/.config/nvim/lua/plugins/lsp.lua | 38 +++++++++- 10 files changed, 161 insertions(+), 51 deletions(-) create mode 100644 .luarc.json create mode 100644 nvim/.config/nvim/.luarc.json create mode 100644 nvim/.config/nvim/after/plugin/autopairs.lua create mode 100644 nvim/.config/nvim/after/plugin/comment.lua create mode 100644 nvim/.config/nvim/after/plugin/cursor.lua create mode 100644 nvim/.config/nvim/after/plugin/indent.lua create mode 100644 nvim/.config/nvim/after/plugin/neoscroll.lua create mode 100644 nvim/.config/nvim/after/plugin/surround.lua diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..b11de3a --- /dev/null +++ b/.luarc.json @@ -0,0 +1,8 @@ +{ + "diagnostics.globals": [ + "vim" + ], + "diagnostics.disable": [ + "undefined-global" + ] +} \ No newline at end of file diff --git a/nvim/.config/nvim/.luarc.json b/nvim/.config/nvim/.luarc.json new file mode 100644 index 0000000..d6e62ee --- /dev/null +++ b/nvim/.config/nvim/.luarc.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://raw.githubusercontent.com/LuaLS/lua-language-server/master/schema/luarc.json", + "diagnostics.globals": ["vim"], +} diff --git a/nvim/.config/nvim/after/plugin/autopairs.lua b/nvim/.config/nvim/after/plugin/autopairs.lua new file mode 100644 index 0000000..46315ae --- /dev/null +++ b/nvim/.config/nvim/after/plugin/autopairs.lua @@ -0,0 +1,20 @@ +local npairs = require("nvim-autopairs") +local Rule = require("nvim-autopairs.rule") + +npairs.setup({ + check_ts = true, + ts_config = { + python = { "string" }, + }, +}) + +npairs.add_rules({ + Rule(" ", " "):with_pair(function(opts) + return vim.tbl_contains({ "()", "[]", "{}" }, opts.line:sub(opts.col - 1, opts.col)) + end), +}) + +npairs.add_rules({ + Rule("'''", "'''", "python"), + Rule('"""', '"""', "python"), +}) diff --git a/nvim/.config/nvim/after/plugin/comment.lua b/nvim/.config/nvim/after/plugin/comment.lua new file mode 100644 index 0000000..ca81062 --- /dev/null +++ b/nvim/.config/nvim/after/plugin/comment.lua @@ -0,0 +1,16 @@ +require("Comment").setup({ + -- pre_hook = require("ts_context_commentstring.integrations.comment_nvim").create_pre_hook(), + toggler = { + line = "cc", -- Line-comment toggle keymap + block = "bc", + }, + opleader = { + line = "c", + block = "b", + }, + extra = { + above = "cO", + below = "co", + eol = "cA", + }, +}) diff --git a/nvim/.config/nvim/after/plugin/cursor.lua b/nvim/.config/nvim/after/plugin/cursor.lua new file mode 100644 index 0000000..e69de29 diff --git a/nvim/.config/nvim/after/plugin/indent.lua b/nvim/.config/nvim/after/plugin/indent.lua new file mode 100644 index 0000000..099006d --- /dev/null +++ b/nvim/.config/nvim/after/plugin/indent.lua @@ -0,0 +1,24 @@ +require("ibl").setup({ + indent = { + char = "┊", --"│", + tab_char = "┊", + }, + scope = { + show_start = false, + show_end = false, + }, + exclude = { + filetypes = { + "help", + "alpha", + "dashboard", + "neo-tree", + "Trouble", + "lazy", + "mason", + "notify", + "togglerterm", + "lazyterm", + }, + }, +}) diff --git a/nvim/.config/nvim/after/plugin/neoscroll.lua b/nvim/.config/nvim/after/plugin/neoscroll.lua new file mode 100644 index 0000000..5ef27bc --- /dev/null +++ b/nvim/.config/nvim/after/plugin/neoscroll.lua @@ -0,0 +1,11 @@ +require("neoscroll").setup({ + mappings = { "", "", "", "", "", "zz", "zt", "zb" }, + hide_cursor = true, + stop_eof = true, + respect_scrolloff = false, + cursor_scrolls_alone = true, + easing_function = "quadratic", + pre_hook = nil, + post_hook = nil, + performance_mode = false, +}) diff --git a/nvim/.config/nvim/after/plugin/surround.lua b/nvim/.config/nvim/after/plugin/surround.lua new file mode 100644 index 0000000..2d6c5bb --- /dev/null +++ b/nvim/.config/nvim/after/plugin/surround.lua @@ -0,0 +1,14 @@ +require("nvim-surround").setup({ + keymaps = { + insert = "s", + insert_line = "S", + normal = "ys", + normal_cur = "yss", + normal_line = "yS", + normal_cur_line = "ySS", + visual = "S", + visual_line = "gS", + delete = "ds", + change = "cs", + }, +}) diff --git a/nvim/.config/nvim/lua/plugins/init.lua b/nvim/.config/nvim/lua/plugins/init.lua index 11a9b4c..e99632a 100644 --- a/nvim/.config/nvim/lua/plugins/init.lua +++ b/nvim/.config/nvim/lua/plugins/init.lua @@ -44,6 +44,14 @@ require("lazy").setup({ "windwp/nvim-ts-autotag", }, }, + { + "kylechui/nvim-surround", + version = "*", + event = "VeryLazy", + config = function() + require("nvim-surround").setup() + end, + }, -- LSP { "neovim/nvim-lspconfig", @@ -55,9 +63,6 @@ require("lazy").setup({ "saghen/blink.cmp", }, }, - { - "nvim-java/nvim-java", - }, { -- Autoformat "stevearc/conform.nvim", event = { "BufWritePre" }, @@ -90,11 +95,9 @@ require("lazy").setup({ end, formatters_by_ft = { lua = { "stylua" }, - -- Conform can also run multiple formatters sequentially - -- python = { "isort", "black" }, - -- + python = { "isort", "black" }, + javascript = { "prettierd", "prettier", stop_after_first = true }, -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, }, }, }, @@ -109,9 +112,6 @@ require("lazy").setup({ "L3MON4D3/LuaSnip", version = "2.*", build = (function() - -- Build Step is needed for regex support in snippets. - -- This step is not supported in many windows environments. - -- Remove the below condition to re-enable on windows. if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then return end @@ -133,42 +133,14 @@ require("lazy").setup({ --- @type blink.cmp.Config opts = { keymap = { - -- 'default' (recommended) for mappings similar to built-in completions - -- to accept ([y]es) the completion. - -- This will auto-import if your LSP supports it. - -- This will expand snippets if the LSP sent a snippet. - -- 'super-tab' for tab to accept - -- 'enter' for enter to accept - -- 'none' for no mappings - -- - -- For an understanding of why the 'default' preset is recommended, - -- you will need to read `:help ins-completion` - -- - -- No, but seriously. Please read `:help ins-completion`, it is really good! - -- - -- All presets have the following mappings: - -- /: move to right/left of your snippet expansion - -- : Open menu or open docs if already open - -- / or /: Select next/previous item - -- : Hide menu - -- : Toggle signature help - -- - -- See :h blink-cmp-config-keymap for defining your own keymap preset = "default", - - -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: - -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps }, appearance = { - -- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font' - -- Adjusts spacing to ensure icons are aligned nerd_font_variant = "mono", }, completion = { - -- By default, you may press `` to show the documentation. - -- Optionally, set `auto_show = true` to show the documentation after a delay. documentation = { auto_show = false, auto_show_delay_ms = 500 }, }, @@ -180,17 +152,7 @@ require("lazy").setup({ }, snippets = { preset = "luasnip" }, - - -- Blink.cmp includes an optional, recommended rust fuzzy matcher, - -- which automatically downloads a prebuilt binary when enabled. - -- - -- By default, we use the Lua implementation instead, but you may enable - -- the rust implementation via `'prefer_rust_with_warning'` - -- - -- See :h blink-cmp-config-fuzzy for more information fuzzy = { implementation = "lua" }, - - -- Shows a signature help window while you type arguments for a function signature = { enabled = true }, }, }, @@ -208,8 +170,6 @@ require("lazy").setup({ opts = {}, -- Optional dependencies dependencies = { { "echasnovski/mini.icons", opts = {} } }, - -- dependencies = { "nvim-tree/nvim-web-devicons" }, -- use if you prefer nvim-web-devicons - -- Lazy loading is not recommended because it is very tricky to make it work correctly in all situations. lazy = false, config = function() require("oil").setup({ @@ -218,6 +178,23 @@ require("lazy").setup({ vim.keymap.set("n", "-", "Oil", { desc = "open parent directory" }) end, }, + { "numToStr/Comment.nvim", opts = {} }, + { "windwp/nvim-autopairs", event = "InsertEnter", opts = {} }, + { "lukas-reineke/indent-blankline.nvim", main = "ibl", opts = {} }, + { + "karb94/neoscroll.nvim", + event = "VeryLazy", + config = function() + require("neoscroll").setup() + end, + }, + { + "sphamba/smear-cursor.nvim", + event = "VeryLazy", + opts = { + smear_between_neighbour_lines = true, + }, + }, }, defaults = { lazy = false, diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua index 7501e1a..4be4bf2 100644 --- a/nvim/.config/nvim/lua/plugins/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -21,16 +21,52 @@ local servers = { lua_ls = { settings = { Lua = { + runtime = { + version = "LuaJIT", + path = { + "?.lua", + "?/init.lua", + vim.fn.stdpath("data") .. "lazy/?.lua", + vim.fn.stdpath("data") .. "lazy/?/init.lua", + }, + }, completion = { callSnippet = "Replace", + keywordSnippet = "Replace", }, diagnostics = { globals = { "vim" }, + useLocalExclude = { "_*" }, + }, + workspace = { + library = { + vim.api.nvim_get_runtime_file("", true), + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + maxPreload = 2000, + preloadFileSize = 50000, + checkThirdParty = false, + }, + telemetry = { enable = false }, + }, + }, + }, + pyright = { + settings = { + pyright = { + disableOrganizeImports = true, + }, + python = { + analysis = { + autoSearchPaths = true, + diagnosticMode = "workspace", + useLibraryCodeForTypes = true, + typeCheckingMode = "basic", }, }, }, }, - ts_ls = {}, } local ensure_installed = vim.tbl_keys(servers or {})