diff --git a/init.lua b/init.lua index 48b203f..655ab45 100755 --- a/init.lua +++ b/init.lua @@ -1,2 +1,26 @@ require("options") -require("plugins") + +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup({ + -- Import plugin configurations + import = "plugins", + + -- Required for the Nix package to function. + performance = { + rtp = { + reset = false, + }, + }, +}) diff --git a/lua/plugins/barbar.lua b/lua/plugins/barbar.lua new file mode 100644 index 0000000..c0d64ff --- /dev/null +++ b/lua/plugins/barbar.lua @@ -0,0 +1,13 @@ +return { + "romgrk/barbar.nvim", + dependencies = { + "lewis6991/gitsigns.nvim", -- OPTIONAL: for git status + "nvim-tree/nvim-web-devicons", -- OPTIONAL: for file icons + }, + init = function() + vim.g.barbar_auto_setup = false + end, + opts = { + auto_hide = 1, + }, +} diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..1c0e3be --- /dev/null +++ b/lua/plugins/colorscheme.lua @@ -0,0 +1,9 @@ +return { + "folke/tokyonight.nvim", + lazy = false, + priority = 1000, + opts = {}, + init = function() + vim.cmd([[ colorscheme tokyonight-night ]]) + end, +} diff --git a/lua/plugins/completion.lua b/lua/plugins/completion.lua new file mode 100644 index 0000000..4796069 --- /dev/null +++ b/lua/plugins/completion.lua @@ -0,0 +1,82 @@ +return { + "hrsh7th/nvim-cmp", + dependencies = { + -- Adds LSP completion capabilities + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-cmdline", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "neovim/nvim-lspconfig", + + -- Snippets + "L3MON4D3/LuaSnip", -- snippet engine + "rafamadriz/friendly-snippets", -- pre-configured snippet texts + "saadparwaiz1/cmp_luasnip", -- nvim-cmp source + }, + init = function() + local cmp = require("cmp") + local luasnip = require("luasnip") + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + require("mason").setup() + require("luasnip.loaders.from_vscode").lazy_load() + require("cmp").setup({ + -- keybinds + mapping = cmp.mapping.preset.insert({ + -- unsure + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.abort(), + + -- return to confirm + [""] = cmp.mapping.confirm({ select = false }), + + -- tab to select prev/next option + -- see: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() + -- that way you will only jump inside the snippet region + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + + -- snippet engine + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + + -- snippet source + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "luasnip" }, + }, { + { name = "buffer" }, + { name = "path" }, + }), + }) + end, +} diff --git a/lua/plugins/completions.lua b/lua/plugins/completions.lua deleted file mode 100755 index a89382b..0000000 --- a/lua/plugins/completions.lua +++ /dev/null @@ -1,64 +0,0 @@ -local cmp = require("cmp") -local luasnip = require("luasnip") -local has_words_before = function() - unpack = unpack or table.unpack - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil -end - -require("mason").setup() -require("luasnip.loaders.from_vscode").lazy_load() -require("cmp").setup({ - -- keybinds - mapping = cmp.mapping.preset.insert({ - -- unsure - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.abort(), - - -- return to confirm - [""] = cmp.mapping.confirm({ select = false }), - - -- tab to select prev/next option - -- see: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - -- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable() - -- that way you will only jump inside the snippet region - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - elseif has_words_before() then - cmp.complete() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), - }), - - -- snippet engine - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - - -- snippet source - sources = cmp.config.sources({ - { name = "nvim_lsp" }, - { name = "luasnip" }, - }, { - { name = "buffer" }, - { name = "path" }, - }), -}) diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua new file mode 100644 index 0000000..d44a943 --- /dev/null +++ b/lua/plugins/gitsigns.lua @@ -0,0 +1,4 @@ +return { + "lewis6991/gitsigns.nvim", + opts = {}, +} diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua deleted file mode 100755 index b268873..0000000 --- a/lua/plugins/init.lua +++ /dev/null @@ -1,181 +0,0 @@ -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release - lazypath, - }) -end -vim.opt.rtp:prepend(lazypath) - -require("lazy").setup({ - performance = { - rtp = { - reset = false, - }, - }, - - -- completions.lua - { - "hrsh7th/nvim-cmp", -- Auto completion - dependencies = { - "neovim/nvim-lspconfig", - - -- Snippet Engine & its associated nvim-cmp source - "L3MON4D3/LuaSnip", - "saadparwaiz1/cmp_luasnip", - - -- Adds LSP completion capabilities - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-cmdline", - - -- Adds a number of user-friendly snippets - "rafamadriz/friendly-snippets", - }, - }, - - -- lspconfig.lua - { - "neovim/nvim-lspconfig", - dependencies = { - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - }, - }, - - { - -- I didn't figure out how to use null-ls/none-ls... - "sbdchd/neoformat", - init = function() - -- Prefer Alejandra for Nix files - vim.g.neoformat_enabled_nix = { "alejandra" } - end, - keys = { - { "lf", "Neoformat", desc = "Format file" }, - }, - }, - - -- nvim-tree.lua - { - "nvim-tree/nvim-tree.lua", - opts = { - view = { - adaptive_size = true, - }, - }, - init = function() - vim.g.loaded_netrw = 1 - vim.g.loaded_netrwPlugin = 1 - end, - keys = { - { "e", "NvimTreeFindFileToggle", desc = "File Explorer" }, - }, - }, - - -- telescope.lua - { - "nvim-telescope/telescope.nvim", - dependencies = { "nvim-lua/plenary.nvim" }, - opts = {}, - keys = { - { "f", "Telescope find_files", desc = "Find files" }, - { "", "Telescope oldfiles", desc = "Recent files" }, - { "sg", "Telescope live_grep", desc = "Live grep" }, - }, - }, - - -- treesitter.lua - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - }, - - -- misc - { - "folke/tokyonight.nvim", -- theme - lazy = false, - priority = 1000, - opts = {}, - init = function() - vim.cmd([[ colorscheme tokyonight-night ]]) - end, - }, - - { - "nvim-lualine/lualine.nvim", -- status line - dependencies = { - "kyazdani42/nvim-web-devicons", -- for filetype icons - }, - opts = { - options = { - -- disable separators - section_separators = "", - component_separators = "", - - -- color scheme - theme = "tokyonight", - }, - -- hide filename - sections = { - lualine_c = {}, - }, - }, - }, - - { - "windwp/nvim-autopairs", - event = "InsertEnter", - opts = {}, -- this is equalent to setup({}) function - }, - - { - "folke/which-key.nvim", - event = "VeryLazy", - init = function() - vim.o.timeoutlen = 300 - end, - opts = {}, - }, - - { - "glepnir/lspsaga.nvim", - dependencies = { - "nvim-treesitter/nvim-treesitter", -- optional - "nvim-tree/nvim-web-devicons", -- optional - }, - opts = { - lightbulb = { - virtual_text = false, - }, - }, - keys = { - { "a", "Lspsaga code_action", desc = "Code Action" }, - }, - }, - - { - "romgrk/barbar.nvim", - dependencies = { - "lewis6991/gitsigns.nvim", -- OPTIONAL: for git status - "nvim-tree/nvim-web-devicons", -- OPTIONAL: for file icons - }, - init = function() - vim.g.barbar_auto_setup = false - end, - opts = { - auto_hide = 1, - }, - }, - - { "lewis6991/gitsigns.nvim", opts = {} }, -}) - --- LSP related -require("plugins.lspconfig") -- utilizes lsp -require("plugins.completions") -- adds completions -require("plugins.treesitter") -- better highlights diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua old mode 100755 new mode 100644 index 7760673..c8f6270 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -1,24 +1,35 @@ -local capabilities = require("cmp_nvim_lsp").default_capabilities() -- needed for nvim-cmp -require("mason").setup() -require("mason-lspconfig").setup() +return { + "neovim/nvim-lspconfig", + dependencies = { + -- Portable package manager + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + }, --- lspconfig -require("lspconfig").lua_ls.setup({ - capabilities = capabilities, -}) + init = function() + local capabilities = require("cmp_nvim_lsp").default_capabilities() -- needed for nvim-cmp + require("mason").setup() + require("mason-lspconfig").setup() -require("lspconfig").nil_ls.setup({ - capabilities = capabilities, - settings = { - ["nil"] = { - formatting = { - command = { "alejandra" }, - }, - nix = { - flake = { - autoArchive = true, + -- lspconfig + require("lspconfig").lua_ls.setup({ + capabilities = capabilities, + }) + + require("lspconfig").nil_ls.setup({ + capabilities = capabilities, + settings = { + ["nil"] = { + formatting = { + command = { "alejandra" }, + }, + nix = { + flake = { + autoArchive = true, + }, + }, }, }, - }, - }, -}) + }) + end, +} diff --git a/lua/plugins/lspsaga.lua b/lua/plugins/lspsaga.lua new file mode 100644 index 0000000..4965249 --- /dev/null +++ b/lua/plugins/lspsaga.lua @@ -0,0 +1,15 @@ +return { + "glepnir/lspsaga.nvim", + dependencies = { + "nvim-treesitter/nvim-treesitter", -- optional + "nvim-tree/nvim-web-devicons", -- optional + }, + opts = { + lightbulb = { + virtual_text = false, + }, + }, + keys = { + { "a", "Lspsaga code_action", desc = "Code Action" }, + }, +} diff --git a/lua/plugins/lualine.lua b/lua/plugins/lualine.lua new file mode 100644 index 0000000..9b3f177 --- /dev/null +++ b/lua/plugins/lualine.lua @@ -0,0 +1,20 @@ +return { + "nvim-lualine/lualine.nvim", -- status line + dependencies = { + "kyazdani42/nvim-web-devicons", -- for filetype icons + }, + opts = { + options = { + -- disable separators + section_separators = "", + component_separators = "", + + -- color scheme + theme = "tokyonight", + }, + -- hide filename + sections = { + lualine_c = {}, + }, + }, +} diff --git a/lua/plugins/neoformat.lua b/lua/plugins/neoformat.lua new file mode 100644 index 0000000..0f20adb --- /dev/null +++ b/lua/plugins/neoformat.lua @@ -0,0 +1,10 @@ +return { + "sbdchd/neoformat", + init = function() + -- Prefer Alejandra for Nix files + vim.g.neoformat_enabled_nix = { "alejandra" } + end, + keys = { + { "lf", "Neoformat", desc = "Format file" }, + }, +} diff --git a/lua/plugins/nvim-autopairs.lua b/lua/plugins/nvim-autopairs.lua new file mode 100644 index 0000000..bfa4ac4 --- /dev/null +++ b/lua/plugins/nvim-autopairs.lua @@ -0,0 +1,5 @@ +return { + "windwp/nvim-autopairs", + event = "InsertEnter", + opts = {}, +} diff --git a/lua/plugins/nvim-tree.lua b/lua/plugins/nvim-tree.lua new file mode 100644 index 0000000..dba4cee --- /dev/null +++ b/lua/plugins/nvim-tree.lua @@ -0,0 +1,15 @@ +return { + "nvim-tree/nvim-tree.lua", + opts = { + view = { + adaptive_size = true, + }, + }, + init = function() + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 + end, + keys = { + { "e", "NvimTreeFindFileToggle", desc = "File Explorer" }, + }, +} diff --git a/lua/plugins/nvim-treesitter.lua b/lua/plugins/nvim-treesitter.lua new file mode 100644 index 0000000..e4e21bd --- /dev/null +++ b/lua/plugins/nvim-treesitter.lua @@ -0,0 +1,24 @@ +return { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + init = function() + require("nvim-treesitter.configs").setup({ + -- A list of parser names, or "all" + ensure_installed = { + "nix", + "lua", + "vim", + }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + auto_install = true, + highlight = { + enable = true, + }, + indent = { + enable = true, + }, + }) + end, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..83605cf --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,10 @@ +return { + "nvim-telescope/telescope.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = {}, + keys = { + { "f", "Telescope find_files", desc = "Find files" }, + { "", "Telescope oldfiles", desc = "Recent files" }, + { "sg", "Telescope live_grep", desc = "Live grep" }, + }, +} diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua deleted file mode 100755 index 1b525ae..0000000 --- a/lua/plugins/treesitter.lua +++ /dev/null @@ -1,18 +0,0 @@ -require("nvim-treesitter.configs").setup({ - -- A list of parser names, or "all" - ensure_installed = { - "nix", - "lua", - "vim", - }, - - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - auto_install = true, - highlight = { - enable = true, - }, - indent = { - enable = true, - }, -}) diff --git a/lua/plugins/which-key.lua b/lua/plugins/which-key.lua new file mode 100644 index 0000000..d80fedd --- /dev/null +++ b/lua/plugins/which-key.lua @@ -0,0 +1,8 @@ +return { + "folke/which-key.nvim", + event = "VeryLazy", + init = function() + vim.o.timeoutlen = 300 + end, + opts = {}, +}