From d97a9a390b8c83b4fa07a83142363c4f7081862f Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Wed, 10 Apr 2024 10:12:30 -0600 Subject: [PATCH] fix nvim path --- .config/nvim/lua/commands.lua | 5 + .config/nvim/lua/mappings.lua | 33 ++++ .config/nvim/lua/options.lua | 38 +++++ .../nvim/lua/plugins/configs/bufferline.lua | 8 + .config/nvim/lua/plugins/configs/cmp.lua | 49 ++++++ .config/nvim/lua/plugins/configs/conform.lua | 6 + .config/nvim/lua/plugins/configs/lazy.lua | 36 ++++ .../nvim/lua/plugins/configs/lspconfig.lua | 73 ++++++++ .../nvim/lua/plugins/configs/telescope.lua | 8 + .../nvim/lua/plugins/configs/treesitter.lua | 9 + .config/nvim/lua/plugins/init.lua | 158 ++++++++++++++++++ .gitignore | 2 +- 12 files changed, 424 insertions(+), 1 deletion(-) create mode 100644 .config/nvim/lua/commands.lua create mode 100644 .config/nvim/lua/mappings.lua create mode 100644 .config/nvim/lua/options.lua create mode 100644 .config/nvim/lua/plugins/configs/bufferline.lua create mode 100644 .config/nvim/lua/plugins/configs/cmp.lua create mode 100644 .config/nvim/lua/plugins/configs/conform.lua create mode 100644 .config/nvim/lua/plugins/configs/lazy.lua create mode 100644 .config/nvim/lua/plugins/configs/lspconfig.lua create mode 100644 .config/nvim/lua/plugins/configs/telescope.lua create mode 100644 .config/nvim/lua/plugins/configs/treesitter.lua create mode 100644 .config/nvim/lua/plugins/init.lua diff --git a/.config/nvim/lua/commands.lua b/.config/nvim/lua/commands.lua new file mode 100644 index 0000000..9cdd6f8 --- /dev/null +++ b/.config/nvim/lua/commands.lua @@ -0,0 +1,5 @@ +-- mason, write correct names only + +vim.api.nvim_create_user_command("MasonInstallAll", function() + vim.cmd "MasonInstall css-lsp html-lsp lua-language-server typescript-language-server stylua prettier" +end, {}) diff --git a/.config/nvim/lua/mappings.lua b/.config/nvim/lua/mappings.lua new file mode 100644 index 0000000..4c700fd --- /dev/null +++ b/.config/nvim/lua/mappings.lua @@ -0,0 +1,33 @@ +local map = vim.keymap.set + +-- general mappings +map("n", "", " w ") +map("i", "jk", "") +map("n", "", " %y+ ") -- copy whole filecontent + +-- nvimtree +map("n", "", " NvimTreeToggle ") +map("n", "", " NvimTreeFocus ") + +-- telescope +map("n", "ff", " Telescope find_files ") +map("n", "fo", " Telescope oldfiles ") +map("n", "fw", " Telescope live_grep ") +map("n", "gt", " Telescope git_status ") + +-- bufferline, cycle buffers +map("n", "", " BufferLineCycleNext ") +map("n", "", " BufferLineCyclePrev ") +map("n", "", " bd ") + +-- comment.nvim +map("n", "/", function() + require("Comment.api").toggle.linewise.current() +end) + +map("v", "/", "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())") + +-- format +map("n", "fm", function() + require("conform").format() +end) diff --git a/.config/nvim/lua/options.lua b/.config/nvim/lua/options.lua new file mode 100644 index 0000000..34f7f92 --- /dev/null +++ b/.config/nvim/lua/options.lua @@ -0,0 +1,38 @@ +local opt = vim.opt + +vim.g.mapleader = " " + +opt.laststatus = 3 -- global statusline +opt.showmode = false + +opt.clipboard = "unnamedplus" + +-- Indenting +opt.expandtab = true +opt.shiftwidth = 2 +opt.smartindent = true +opt.tabstop = 2 +opt.softtabstop = 2 + +opt.fillchars = { eob = " " } +opt.ignorecase = true +opt.smartcase = true +opt.mouse = "a" + +-- Numbers +opt.number = true +opt.ruler = false + +opt.signcolumn = "yes" +opt.splitbelow = true +opt.splitright = true +opt.termguicolors = true +opt.timeoutlen = 400 +opt.undofile = true + +opt.timeoutlen = 400 +opt.updatetime = 250 + +-- add binaries installed by mason.nvim to path +local is_windows = vim.loop.os_uname().sysname == "Windows_NT" +vim.env.PATH = vim.env.PATH .. (is_windows and ";" or ":") .. vim.fn.stdpath "data" .. "/mason/bin" diff --git a/.config/nvim/lua/plugins/configs/bufferline.lua b/.config/nvim/lua/plugins/configs/bufferline.lua new file mode 100644 index 0000000..15fd986 --- /dev/null +++ b/.config/nvim/lua/plugins/configs/bufferline.lua @@ -0,0 +1,8 @@ +require("bufferline").setup { + options = { + themable = true, + offsets = { + { filetype = "NvimTree", highlight = "NvimTreeNormal" }, + }, + }, +} diff --git a/.config/nvim/lua/plugins/configs/cmp.lua b/.config/nvim/lua/plugins/configs/cmp.lua new file mode 100644 index 0000000..74b471a --- /dev/null +++ b/.config/nvim/lua/plugins/configs/cmp.lua @@ -0,0 +1,49 @@ +local cmp = require "cmp" + +cmp.setup { + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.confirm { select = true }, + + -- luasnip + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").expand_or_jumpable() then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-expand-or-jump", true, true, true), "") + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").jumpable(-1) then + vim.fn.feedkeys(vim.api.nvim_replace_termcodes("luasnip-jump-prev", true, true, true), "") + else + fallback() + end + end, { + "i", + "s", + }), + }, + sources = cmp.config.sources { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "nvim_lua" }, + { name = "path" }, + }, +} diff --git a/.config/nvim/lua/plugins/configs/conform.lua b/.config/nvim/lua/plugins/configs/conform.lua new file mode 100644 index 0000000..418195e --- /dev/null +++ b/.config/nvim/lua/plugins/configs/conform.lua @@ -0,0 +1,6 @@ +require("conform").setup { + formatters_by_ft = { + lua = { "stylua" }, + javascript = { { "prettier" } }, + }, +} diff --git a/.config/nvim/lua/plugins/configs/lazy.lua b/.config/nvim/lua/plugins/configs/lazy.lua new file mode 100644 index 0000000..ea029ab --- /dev/null +++ b/.config/nvim/lua/plugins/configs/lazy.lua @@ -0,0 +1,36 @@ +return { + install = { colorscheme = { "nightfox" } }, + performance = { + rtp = { + disabled_plugins = { + "2html_plugin", + "tohtml", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + "tutor", + "rplugin", + "syntax", + "synmenu", + "optwin", + "compiler", + "bugreport", + "ftplugin", + }, + }, + }, +} diff --git a/.config/nvim/lua/plugins/configs/lspconfig.lua b/.config/nvim/lua/plugins/configs/lspconfig.lua new file mode 100644 index 0000000..de71c52 --- /dev/null +++ b/.config/nvim/lua/plugins/configs/lspconfig.lua @@ -0,0 +1,73 @@ +-- Global mappings. +vim.keymap.set("n", "e", vim.diagnostic.open_float) +vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) +vim.keymap.set("n", "]d", vim.diagnostic.goto_next) +vim.keymap.set("n", "q", vim.diagnostic.setloclist) + +-- Use LspAttach autocommand to only map the following keys +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("UserLspConfig", {}), + callback = function(ev) + -- Enable completion triggered by + vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" + + local opts = { buffer = ev.buf } + vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) + vim.keymap.set("n", "", vim.lsp.buf.signature_help, opts) + vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set("n", "wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set("n", "D", vim.lsp.buf.type_definition, opts) + vim.keymap.set("n", "rn", vim.lsp.buf.rename, opts) + vim.keymap.set({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + -- vim.keymap.set("n", "f", function() + -- vim.lsp.buf.format { async = true } + -- end, opts) + end, +}) + +local capabilities = vim.lsp.protocol.make_client_capabilities() + +capabilities.textDocument.completion.completionItem = { + documentationFormat = { "markdown", "plaintext" }, + snippetSupport = true, + preselectSupport = true, + insertReplaceSupport = true, + labelDetailsSupport = true, + deprecatedSupport = true, + commitCharactersSupport = true, + tagSupport = { valueSet = { 1 } }, + resolveSupport = { + properties = { + "documentation", + "detail", + "additionalTextEdits", + }, + }, +} +-- Setup language servers. +local lspconfig = require "lspconfig" + +lspconfig.lua_ls.setup { + capabilities = capabilities, + settings = { + Lua = { + diagnostics = { globals = { "vim" } }, + }, + }, +} + +-- setup multiple servers with same default options +local servers = { "tsserver", "html", "cssls" } + +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + capabilities = capabilities, + } +end diff --git a/.config/nvim/lua/plugins/configs/telescope.lua b/.config/nvim/lua/plugins/configs/telescope.lua new file mode 100644 index 0000000..0ac9389 --- /dev/null +++ b/.config/nvim/lua/plugins/configs/telescope.lua @@ -0,0 +1,8 @@ +require("telescope").setup { + defaults = { + sorting_strategy = "ascending", + layout_config = { + horizontal = { prompt_position = "top" }, + }, + }, +} diff --git a/.config/nvim/lua/plugins/configs/treesitter.lua b/.config/nvim/lua/plugins/configs/treesitter.lua new file mode 100644 index 0000000..f3435d5 --- /dev/null +++ b/.config/nvim/lua/plugins/configs/treesitter.lua @@ -0,0 +1,9 @@ +require("nvim-treesitter.configs").setup { + ensure_installed = { "lua", "vim", "vimdoc", "tsx", "html", "css", "typescript", "javascript" }, + + highlight = { + enable = true, + use_languagetree = true, + }, + indent = { enable = true }, +} diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua new file mode 100644 index 0000000..bb31b69 --- /dev/null +++ b/.config/nvim/lua/plugins/init.lua @@ -0,0 +1,158 @@ +local plugins = { + { lazy = true, "nvim-lua/plenary.nvim" }, + + { "catppuccin/nvim", name = "catppuccin", priority = 1000 }, + + -- file tree + { + "nvim-tree/nvim-tree.lua", + cmd = { "NvimTreeToggle", "NvimTreeFocus" }, + config = function() + require("nvim-tree").setup() + end, + }, + + -- icons, for UI related plugins + { + "nvim-tree/nvim-web-devicons", + config = function() + require("nvim-web-devicons").setup() + end, + }, + + -- syntax highlighting + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + require "plugins.configs.treesitter" + end, + }, + + -- buffer + tab line + { + "akinsho/bufferline.nvim", + event = "BufReadPre", + config = function() + require "plugins.configs.bufferline" + end, + }, + + -- statusline + + { + "echasnovski/mini.statusline", + config = function() + require("mini.statusline").setup { set_vim_settings = false } + end, + }, + + -- we use cmp plugin only when in insert mode + -- so lets lazyload it at InsertEnter event, to know all the events check h-events + -- completion , now all of these plugins are dependent on cmp, we load them after cmp + { + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + -- cmp sources + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lsp", + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lua", + + -- snippets + --list of default snippets + "rafamadriz/friendly-snippets", + + -- snippets engine + { + "L3MON4D3/LuaSnip", + config = function() + require("luasnip.loaders.from_vscode").lazy_load() + end, + }, + + -- autopairs , autocompletes ()[] etc + { + "windwp/nvim-autopairs", + config = function() + require("nvim-autopairs").setup() + + -- cmp integration + local cmp_autopairs = require "nvim-autopairs.completion.cmp" + local cmp = require "cmp" + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, + }, + }, + config = function() + require "plugins.configs.cmp" + end, + }, + + { + "williamboman/mason.nvim", + build = ":MasonUpdate", + cmd = { "Mason", "MasonInstall" }, + config = function() + require("mason").setup() + end, + }, + + -- lsp + { + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + config = function() + require "plugins.configs.lspconfig" + end, + }, + + -- formatting , linting + { + "stevearc/conform.nvim", + lazy = true, + config = function() + require "plugins.configs.conform" + end, + }, + + -- indent lines + { + "lukas-reineke/indent-blankline.nvim", + event = { "BufReadPre", "BufNewFile" }, + config = function() + require("ibl").setup() + end, + }, + + -- files finder etc + { + "nvim-telescope/telescope.nvim", + cmd = "Telescope", + config = function() + require "plugins.configs.telescope" + end, + }, + + -- git status on signcolumn etc + { + "lewis6991/gitsigns.nvim", + event = { "BufReadPre", "BufNewFile" }, + config = function() + require("gitsigns").setup() + end, + }, + + -- comment plugin + { + "numToStr/Comment.nvim", + lazy = true, + config = function() + require("Comment").setup() + end, + }, +} + +require("lazy").setup(plugins, require "plugins.configs.lazy") diff --git a/.gitignore b/.gitignore index fbb3fc2..759b8c7 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ !.config/alacritty/* !.config/nvim -!.config/nvim/* +!.config/nvim/** !.config/dunst !.config/dunst/*