diff --git a/home-manager/common/programs/nvim/config/init.lua b/home-manager/common/programs/nvim/config/init.lua index d5244d9..3918bb8 100644 --- a/home-manager/common/programs/nvim/config/init.lua +++ b/home-manager/common/programs/nvim/config/init.lua @@ -1,86 +1,31 @@ -- --- Vim Options +-- Bootstrap lazy.nvim -- --- Disable vim's built in file explorer -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 - --- {{{ General Configuration -vim.opt.termguicolors = true -- set termguicolors to enable highlight groups -vim.opt.number = true -- print line numbers -vim.opt.showmode = false -- if in insert, replace or visual mode put a message on the last line -vim.opt.swapfile = false -- disable swap file -vim.opt.clipboard = 'unnamedplus' -- use the system clipboard as the default register --- }}} - --- {{{ Spaces & Tabs -vim.opt.tabstop = 2 -- number of visual spaces per TAB -vim.opt.softtabstop = 2 -- number of spaces in tab when editing -vim.opt.shiftwidth = 2 -- number of spaces to use for autoindent -vim.opt.expandtab = true -- tabs are space -vim.opt.autoindent = true -vim.opt.copyindent = true -- copy indent from the previous line --- }}} - --- {{{ Keybinds -vim.g.mapleader = ' ' - -local opts = { noremap = true, silent = true } -local map = vim.api.nvim_set_keymap - - -map('n', 't', ':NvimTreeToggle', opts) --- }}} - --- --- Gruvbox Material --- - --- For dark version -vim.opt.background = 'dark' - --- Set contrast -vim.g.gruvbox_material_background = 'hard' - --- For better performance -vim.g.gruvbox_material_better_performance = 0 - --- To disable italic in `Comment`, set this option to `1` -vim.g.gruvbox_material_disable_italic_comment = 1 - --- To enable bold in function name just like the original gruvbox, set this option to `1` -vim.g.gruvbox_material_enable_bold = 0 - --- To enable italic in this color scheme, set this option to `1` -vim.g.gruvbox_material_enable_italic = 1 - --- Set the colorscheme -vim.cmd [[colorscheme gruvbox-material]] +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) -- --- Load and run our libraries +-- Load our configurations -- --- load defaults -require('nvim-tree').setup() -require('Comment').setup() -require('gitsigns').setup() - --- user -require('user.lspconfig') -require('user.nvim-cmp') -require('user.lualine') - --- user.config -require('user.config.server_configurations') +require('configs.options') --- Enable syntax highlighting -require('nvim-treesitter.configs').setup { - highlight = { - enable = true, - } -} +-- +-- Load our plugin specs +-- + +require('lazy').setup('plugins') diff --git a/home-manager/common/programs/nvim/config/lua/configs/options.lua b/home-manager/common/programs/nvim/config/lua/configs/options.lua new file mode 100644 index 0000000..4e498c6 --- /dev/null +++ b/home-manager/common/programs/nvim/config/lua/configs/options.lua @@ -0,0 +1,17 @@ +-- Keybinds +vim.g.mapleader = ' ' + +-- General +vim.opt.number = true +vim.opt.showmode = false +vim.opt.swapfile = false +vim.opt.clipboard = 'unnamedplus' + +-- Tabs & spaces +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true +vim.opt.autoindent = true +vim.opt.copyindent = true + diff --git a/home-manager/common/programs/nvim/config/lua/plugins/coding.lua b/home-manager/common/programs/nvim/config/lua/plugins/coding.lua new file mode 100644 index 0000000..cbf7614 --- /dev/null +++ b/home-manager/common/programs/nvim/config/lua/plugins/coding.lua @@ -0,0 +1,165 @@ +return { + -- + -- LSP Configuration + -- + + { + 'neovim/nvim-lspconfig', + event = { 'BufReadPost', 'BufNewFile' }, + dependencies = { + 'hrsh7th/nvim-cmp', -- Autocompletion plugin + 'hrsh7th/cmp-nvim-lsp', -- LSP source for nvim-cmp + 'saadparwaiz1/cmp_luasnip', -- Snippets source for nvim-cmp + 'L3MON4D3/LuaSnip', -- Snippets plugin + }, + config = function () + -- + -- Setup language servers. + -- + + local lspconfig = require('lspconfig') + + -- Lua + lspconfig.lua_ls.setup { + on_init = function(client) + local path = client.workspace_folders[1].name + if not vim.loop.fs_stat(path..'/.luarc.json') and not vim.loop.fs_stat(path..'/.luarc.jsonc') then + client.config.settings = vim.tbl_deep_extend('force', client.config.settings, { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT' + }, + -- Make the server aware of Neovim runtime files + workspace = { + checkThirdParty = false, + library = { + vim.env.VIMRUNTIME + -- "${3rd}/luv/library" + -- "${3rd}/busted/library", + } + -- or pull in all of 'runtimepath'. NOTE: this is a lot slower + -- library = vim.api.nvim_get_runtime_file("", true) + } + } + }) + + client.notify("workspace/didChangeConfiguration", { settings = client.config.settings }) + end + return true + end + } + + -- Haskell + lspconfig.hls.setup{ + filetypes = { 'haskell', 'lhaskell', 'cabal' }, + } + + -- Nix + lspconfig.nil_ls.setup{} + + + -- + -- Global mappings + -- + + -- See `:help vim.diagnostic.*` for documentation on any of the below functions + 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 + -- after the language server attaches to the current buffer + vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + 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, + }) + + + -- + -- Autocompletion + -- + + -- Add additional capabilities supported by nvim-cmp + local capabilities = require("cmp_nvim_lsp").default_capabilities() + + -- Enable some language servers with the additional completion capabilities offered by nvim-cmp + local servers = { 'clangd', 'rust_analyzer', 'pyright', 'tsserver' } + for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + -- on_attach = my_custom_on_attach, + capabilities = capabilities, + } + end + + -- luasnip setup + local luasnip = require 'luasnip' + + -- nvim-cmp setup + local cmp = require 'cmp' + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), -- Up + [''] = cmp.mapping.scroll_docs(4), -- Down + -- C-b (back) C-f (forward) for snippet placeholder navigation. + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + 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' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, + } + end + }, +} + diff --git a/home-manager/common/programs/nvim/config/lua/plugins/colorscheme.lua b/home-manager/common/programs/nvim/config/lua/plugins/colorscheme.lua new file mode 100644 index 0000000..ef5101d --- /dev/null +++ b/home-manager/common/programs/nvim/config/lua/plugins/colorscheme.lua @@ -0,0 +1,21 @@ +return { + -- + -- Modified version of gruvbox + -- + + { + 'sainnhe/gruvbox-material', + lazy = false, + priority = 1000, + config = function() + vim.o.termguicolors = true + vim.o.background = 'dark' + + vim.g.gruvbox_material_background = 'hard' + vim.g.gruvbox_material_better_performance = 1 + + vim.cmd([[colorscheme gruvbox-material]]) + end, + }, +} + diff --git a/home-manager/common/programs/nvim/config/lua/plugins/editor.lua b/home-manager/common/programs/nvim/config/lua/plugins/editor.lua new file mode 100644 index 0000000..e9478aa --- /dev/null +++ b/home-manager/common/programs/nvim/config/lua/plugins/editor.lua @@ -0,0 +1,85 @@ +return { + -- + -- Treesitter + -- + + { + 'nvim-treesitter/nvim-treesitter', + build = ":TSUpdate", + config = function() + local configs = require('nvim-treesitter.configs') + + configs.setup({ + auto_install = true, + highlight = { enable = true }, + indent = { enable = true }, + }) + end + }, + + + -- + -- Fuzzy Finder + -- + + { + 'nvim-telescope/telescope.nvim', + tag = '0.1.3', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', + }, + keys = { + { 'ff', 'Telescope find_files', desc = 'Find Files' }, + { 'fg', 'Telescope live_grep' , desc = 'Live Grep' }, + { 'fb', 'Telescope buffers' , desc = 'Buffers' }, + { 'fh', 'Telescope help_tags' , desc = 'Help Tags' }, + }, + config = function() + require('telescope').setup() + end + }, + + + -- + -- Commenting + -- + + { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end + }, + + + -- + -- Git Commands + -- + + { + 'kdheepak/lazygit.nvim', + dependencies = { + 'nvim-lua/plenary.nvim' + }, + keys = { + { 'gg', 'LazyGit', desc = 'LazyGit' }, + } + }, + + + -- + -- Display Keybindings + -- + + { + 'folke/which-key.nvim', + event = 'VeryLazy', + init = function() + vim.o.timeout = true + vim.o.timeoutlen = 300 + end, + opts = { }, + }, +} + diff --git a/home-manager/common/programs/nvim/config/lua/plugins/ui.lua b/home-manager/common/programs/nvim/config/lua/plugins/ui.lua new file mode 100644 index 0000000..c0b24cb --- /dev/null +++ b/home-manager/common/programs/nvim/config/lua/plugins/ui.lua @@ -0,0 +1,60 @@ +return { + -- + -- File explorer + -- + + { + 'nvim-neo-tree/neo-tree.nvim', + dependencies = { + 'nvim-lua/plenary.nvim', + 'nvim-tree/nvim-web-devicons', + 'MunifTanjim/nui.nvim', + }, + keys = { + { '/', 'Neotree reveal', desc = 'Neotree' }, + }, + opts = { + close_if_last_window = true, + } + }, + + + -- + -- Statusline + -- + + { + 'nvim-lualine/lualine.nvim', + event = 'VeryLazy', + dependencies = { + 'nvim-tree/nvim-web-devicons', + }, + config = function() + require('lualine').setup { + options = { + icons_enabled = true, + theme = 'gruvbox-material', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + globalstatus = true, + extensions = { + 'neotree' + }, + } + } + end, + }, + + + -- + -- Git decorations + -- + + { + 'lewis6991/gitsigns.nvim', + config = function() + require('gitsigns').setup() + end + } +} + diff --git a/home-manager/common/programs/nvim/config/lua/user/config/server_configurations.lua b/home-manager/common/programs/nvim/config/lua/user/config/server_configurations.lua deleted file mode 100644 index 2784de0..0000000 --- a/home-manager/common/programs/nvim/config/lua/user/config/server_configurations.lua +++ /dev/null @@ -1,33 +0,0 @@ --- Setup language servers -require'lspconfig'.clangd.setup{} -require'lspconfig'.nil_ls.setup{} - --- haskell-language-server -require'lspconfig'.hls.setup { - filetypes = { 'haskell', 'lhaskell', 'cabal' }, -} - --- lua-language-server -require'lspconfig'.lua_ls.setup { - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = 'LuaJIT', - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = {'vim'}, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - checkThirdParty = false, - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - }, - }, -} diff --git a/home-manager/common/programs/nvim/config/lua/user/lspconfig.lua b/home-manager/common/programs/nvim/config/lua/user/lspconfig.lua deleted file mode 100644 index e278cc1..0000000 --- a/home-manager/common/programs/nvim/config/lua/user/lspconfig.lua +++ /dev/null @@ -1,40 +0,0 @@ --- Global mappings. --- See `:help vim.diagnostic.*` for documentation on any of the below functions -vim.keymap.set('n', 'de', vim.diagnostic.enable) -vim.keymap.set('n', 'dd', vim.diagnostic.disable) -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 --- after the language server attaches to the current buffer -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' - - -- Buffer local mappings. - -- See `:help vim.lsp.*` for documentation on any of the below functions - 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', '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, -}) - diff --git a/home-manager/common/programs/nvim/config/lua/user/lualine.lua b/home-manager/common/programs/nvim/config/lua/user/lualine.lua deleted file mode 100644 index f7a8817..0000000 --- a/home-manager/common/programs/nvim/config/lua/user/lualine.lua +++ /dev/null @@ -1,87 +0,0 @@ --- Use external source for diff -local function diff_source() - local gitsigns = vim.b.gitsigns_status_dict - if gitsigns then - return { - added = gitsigns.added, - modified = gitsigns.changed, - removed = gitsigns.removed - } - end -end - --- Configure the statusline -require('lualine').setup { - options = { - -- Set our theme and icon status - icons_enabled = true, - theme = 'gruvbox-material', - - -- Define our seperators - component_separators = { left = '', right = ''}, - section_separators = { left = '', right = ''}, - - -- Disable some filetypes - disabled_filetypes = { - statusline = {}, - winbar = {}, - }, - - -- If current filetype in in this list it'll - -- always be drawn as inactive statusline - ignore_focus = {}, - - -- When set to true, left sections i.e. 'a','b' and 'c' - -- can't take over the entire statusline even - -- if neither of 'x', 'y' or 'z' are present. - always_divide_middle = true, - - -- enable global statusline (have a single statusline - -- at bottom of neovim instead of one for every window). - globalstatus = true, - - -- sets how often lualine should refreash it's contents (in ms) - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - } - }, - - -- Setup our active statusline components - sections = { - lualine_a = {'mode'}, - lualine_b = { {'FugitiveHead', icon = ''}, {'diff', source = diff_source}, 'diagnostics'}, - lualine_c = {'filename'}, - lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_y = {'progress'}, - lualine_z = {'location'} - }, - - -- Setup our inactive statusline components - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {'filename'}, - lualine_x = {'location'}, - lualine_y = {}, - lualine_z = {} - }, - - -- Setup our tabline components - tabline = { - lualine_a = {'buffers'}, - lualine_b = {'searchcount'}, - lualine_c = {}, - lualine_x = {}, - lualine_y = {}, - lualine_z = {'tabs'} - }, - - -- Setup our winbar components - winbar = {}, - inactive_winbar = {}, - - -- Load our extensions - extensions = {'fugitive', 'nvim-tree'} -} diff --git a/home-manager/common/programs/nvim/config/lua/user/nvim-cmp.lua b/home-manager/common/programs/nvim/config/lua/user/nvim-cmp.lua deleted file mode 100644 index 56cba65..0000000 --- a/home-manager/common/programs/nvim/config/lua/user/nvim-cmp.lua +++ /dev/null @@ -1,60 +0,0 @@ --- Add additional capabilities supported by nvim-cmp -local capabilities = require("cmp_nvim_lsp").default_capabilities() - -local lspconfig = require('lspconfig') - --- Enable some language servers with the additional completion capabilities offered by nvim-cmp -local servers = { 'clangd', 'lua_ls', 'nil_ls' } -for _, lsp in ipairs(servers) do - lspconfig[lsp].setup { - -- on_attach = my_custom_on_attach, - capabilities = capabilities, - } -end - --- luasnip setup -local luasnip = require 'luasnip' - --- nvim-cmp setup -local cmp = require 'cmp' -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.abort(), - [''] = cmp.mapping.scroll_docs(-4), -- Up - [''] = cmp.mapping.scroll_docs(4), -- Down - -- C-b (back) C-f (forward) for snippet placeholder navigation. - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then - luasnip.expand_or_jump() - 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' }), - }), - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, -} - diff --git a/home-manager/common/programs/nvim/default.nix b/home-manager/common/programs/nvim/default.nix index c926238..beee5b7 100644 --- a/home-manager/common/programs/nvim/default.nix +++ b/home-manager/common/programs/nvim/default.nix @@ -1,59 +1,24 @@ { inputs, outputs, lib, config, pkgs, ... }: { - - home.packages = with pkgs.unstable; [ - # Language servers - clang-tools # C, C++, Objective C/C++, OpenCL, CUDA, and RenderScript - haskell-language-server # Haskell - lua-language-server # Lua - nil # Nix - ]; - programs.neovim = { enable = true; - package = pkgs.unstable.neovim-unwrapped; - plugins = with pkgs.unstable.vimPlugins; [ - # Install all grammar packages - # nvim-treesitter.withAllGrammars - - # Or specific grammar packages only - (nvim-treesitter.withPlugins (p: [ - p.c - p.lua - p.nix - ])) - - # Quality of Life Enhancements - comment-nvim # Smart and powerful commenting - - # User Interface - gruvbox-material # Theme - dashboard-nvim # Start screen - nvim-tree-lua # File explorer - lualine-nvim # Statusline - - # Git Integration - vim-fugitive # Call any arbitary git command - gitsigns-nvim # Git decorations - - # Autocompletion - nvim-lspconfig # Collection of configurations for built-in LSP client - nvim-cmp # Autocompletion plugin - cmp-nvim-lsp # LSP source for nvim-cmp - cmp_luasnip # Snippets source for nvim-cmp - luasnip # Snippets plugin - package = pkgs.neovim-nightly; + defaultEditor = true; + extraPackages = with pkgs; [ # Misc - vim-shellcheck # Static analysis tool for shell scripts - markdown-preview-nvim # Preview markdown in browser - - # Dependencies - nvim-web-devicons # Provides icons + lazygit + # Required for nvim-treesitter + gcc + # Required for telescope.nvim + fd + ripgrep + # Language server packages + nil + haskell-language-server + lua-language-server ]; }; xdg.configFile.nvim = { source = ./config; recursive = true; }; - }