diff --git a/homeConfig/home.nix b/homeConfig/home.nix index 91144a1..26f7637 100644 --- a/homeConfig/home.nix +++ b/homeConfig/home.nix @@ -2,7 +2,7 @@ { programs.home-manager.enable = true; - imports = [ (import ./modules/default.nix) ]; + imports = [ (import ./modules) ]; home.stateVersion = "22.11"; home.username = "bryan"; diff --git a/homeConfig/modules/default.nix b/homeConfig/modules/default.nix index 3d47edb..a42be7e 100644 --- a/homeConfig/modules/default.nix +++ b/homeConfig/modules/default.nix @@ -2,16 +2,16 @@ { imports = [ - ./alacritty/default.nix - ./bash/default.nix - ./browsers/default.nix - ./corn/default.nix - ./fun/default.nix - ./git/default.nix - ./gpg/default.nix - ./gui/default.nix - ./neovim/default.nix - ./security/default.nix - ./utils/default.nix + ./alacritty + ./bash + ./browsers + ./corn + ./fun + ./git + ./gpg + ./gui + ./neovim + ./security + ./utils ]; } diff --git a/homeConfig/modules/gui/config/sway.nix b/homeConfig/modules/gui/config/sway.nix index 9dc036d..88b73ea 100644 --- a/homeConfig/modules/gui/config/sway.nix +++ b/homeConfig/modules/gui/config/sway.nix @@ -46,7 +46,7 @@ in position = "top"; statusCommand = ''while :; do echo "$(free -h | awk '/^Mem/ {print $3}') '|' $(date +'%I:%M:%S %p') '|' $(date +'%m-%d-%Y')"; sleep 1; done''; fonts = { - names = [ "Noto Sans" "Noto Emoji" "Noto Color Emoji" ]; + names = [ "Noto Sans" ]; size = 10.0; }; colors = { diff --git a/homeConfig/modules/neovim/config/init.nix b/homeConfig/modules/neovim/config/init.nix index 81846e0..df45ee1 100644 --- a/homeConfig/modules/neovim/config/init.nix +++ b/homeConfig/modules/neovim/config/init.nix @@ -1,5 +1,9 @@ '' +vim.o.relativenumber = true +vim.o.number = true +vim.cmd('highlight LineNr ctermfg=DarkGray') + vim.opt.tabstop = 2 vim.opt.shiftwidth = 2 vim.opt.expandtab = true @@ -13,105 +17,6 @@ vim.cmd([[ au BufRead,BufNewFile *.purs set filetype=purescript ]]) -require("config.lazy") - -local lsp = require("lsp-zero").preset({}) - -lsp.on_attach(function(client, bufnr) - lsp.default_keymaps({ buffer = bufnr }) -end) - -lsp.setup_servers({ - "tsserver", - "eslint", - "hls", - "pyright", - "nil_ls", - "cssls", - "html", - "jsonls", - "diagnosticls", - "lua_ls", - "marksman", - "purescriptls", - "tailwindcss", - "bashls", -}) - -require("lspconfig").lua_ls.setup(lsp.nvim_lua_ls()) - -lsp.setup() - -local cmp = require("cmp") -cmp.setup({ - snippet = { - expand = function(args) - require("luasnip").lsp_expand(args.body) - end, - }, - sources = { - { name = "nvim_lsp" }, - { name = "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 - -local luasnip = require("luasnip") - -cmp.setup({ - enabled = function() - -- disable completion in comments - local context = require("cmp.config.context") - -- keep command mode completion enabled when cursor is in a comment - if vim.api.nvim_get_mode().mode == "c" then - return true - else - return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") - end - end, - mapping = { - [""] = 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() - -- they 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" }), - - [""] = cmp.mapping({ - i = function(fallback) - if cmp.visible() and cmp.get_active_entry() then - cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) - else - fallback() - end - end, - s = cmp.mapping.confirm({ select = true }), - c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), - }), - }, -}) vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { -- Disable virtual_text @@ -121,4 +26,10 @@ vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagn require("notify").setup({ background_colour = "#000000", }) + + +vim.api.nvim_set_keymap('n', '', 'zz', {noremap = true}) +vim.api.nvim_set_keymap('n', '', 'zz', {noremap = true}) +vim.api.nvim_set_keymap('n', '', 'zz', {noremap = true}) +vim.api.nvim_set_keymap('n', '', 'zz', {noremap = true}) '' diff --git a/homeConfig/modules/neovim/config/plugins.nix b/homeConfig/modules/neovim/config/plugins.nix deleted file mode 100644 index 476cc3a..0000000 --- a/homeConfig/modules/neovim/config/plugins.nix +++ /dev/null @@ -1,66 +0,0 @@ -{ pkgs, ... }: - -#let -# github-theme = pkgs.vimUtils.buildVimPlugin { -# name = "github-theme"; -# src = builtins.fetchTarball { -# url = "https://github.com/projekt0n/github-nvim-theme/archive/refs/tags/v1.0.0.tar.gz"; -# sha256 = "15c65qw1sgw3v5wrwbg5f1fqb82qq1yr44g2nrwb7b7m134jyr1h"; -# }; -# }; -# -#in -with pkgs.vimPlugins; -[ -# { -# plugin = github-theme; -# config = '' -# lua << EOF -# vim.cmd('colorscheme github_dark_high_contrast') -# EOF -# ''; -# } - - { plugin = lazygit-nvim; } - - { - plugin = LazyVim; - config = '' - lua << EOF - return { - {'williamboman/mason.nvim', enabled = false }, - {'williamboman/mason-lspconfig.nvim', enabled = false }, - {'nvim-treesitter/nvim-treesitter', enabled = false }, - } - EOF - ''; - } - - { - plugin = lsp-zero-nvim; - config = '' - lua << EOF - branch = 'v2.x' - requires = { - {'neovim/nvim-lspconfig'}, - {'hrsh7th/nvim-cmp'}, - {'hrsh7th/cmp-nvim-lsp'}, - {'L3MON4D3/LuaSnip'}, - } - EOF - ''; - } - - { - plugin = nvim-treesitter.withAllGrammars; - config = '' - lua << EOF - require'nvim-treesitter.configs'.setup { - highlight = { - enable = true, - }, - } - EOF - ''; - } -] diff --git a/homeConfig/modules/neovim/config/plugins/default.nix b/homeConfig/modules/neovim/config/plugins/default.nix new file mode 100644 index 0000000..12ba519 --- /dev/null +++ b/homeConfig/modules/neovim/config/plugins/default.nix @@ -0,0 +1,19 @@ +{ pkgs, lib, ... }: + +let + theme = import ./theme; + treesitter = import ./treesitter; + editing = import ./editing; + lsp = import ./lsp; + luasnip = import ./luasnip; + tools = import ./tools; + +in +builtins.concatMap (dir: dir { inherit pkgs lib; }) [ + theme + treesitter + editing + lsp + luasnip + tools +] diff --git a/homeConfig/modules/neovim/config/plugins/editing/default.nix b/homeConfig/modules/neovim/config/plugins/editing/default.nix new file mode 100644 index 0000000..81886ea --- /dev/null +++ b/homeConfig/modules/neovim/config/plugins/editing/default.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: + +with pkgs.vimPlugins; +[ + { plugin = indent-blankline-nvim; } + { plugin = auto-pairs; } + { plugin = vim-css-color; } +] diff --git a/homeConfig/modules/neovim/config/plugins/lsp/default.nix b/homeConfig/modules/neovim/config/plugins/lsp/default.nix new file mode 100644 index 0000000..5619496 --- /dev/null +++ b/homeConfig/modules/neovim/config/plugins/lsp/default.nix @@ -0,0 +1,93 @@ +{ pkgs, ... }: + +with pkgs.vimPlugins; +[ + { plugin = lsp-zero-nvim; + config = '' + lua << EOF + local lsp = require('lsp-zero').preset({}) + + lsp.on_attach(function(client, bufnr) + lsp.default_keymaps({buffer = bufnr}) + end) + + lsp.setup_servers({ + "tsserver", + "eslint", + "hls", + "pyright", + "nil_ls", + "cssls", + "html", + "jsonls", + "diagnosticls", + "lua_ls", + "marksman", + "purescriptls", + "tailwindcss", + "bashls", + }) + + lsp.setup() + EOF + ''; + } + + { plugin = null-ls-nvim; } + { plugin = nvim-lspconfig; } + { plugin = cmp-nvim-lsp; } + + { plugin = nvim-cmp; + config = '' + lua << EOF + 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 + + local luasnip = require("luasnip") + local cmp = require'cmp' + + cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + end, + }, + + window = { + completion = cmp.config.window.bordered(), + documentation = cmp.config.window.bordered(), + }, + + enabled = function() + -- disable completion in comments + local context = require("cmp.config.context") + -- keep command mode completion enabled when cursor is in a comment + if vim.api.nvim_get_mode().mode == "c" then + return true + else + return not context.in_treesitter_capture("comment") and not context.in_syntax_group("Comment") + end + 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 }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, -- For luasnip users. + }, { + { name = 'buffer' }, + }) + }) + EOF + ''; + } +] diff --git a/homeConfig/modules/neovim/config/plugins/luasnip/default.nix b/homeConfig/modules/neovim/config/plugins/luasnip/default.nix new file mode 100644 index 0000000..65c25f9 --- /dev/null +++ b/homeConfig/modules/neovim/config/plugins/luasnip/default.nix @@ -0,0 +1,26 @@ +{ pkgs, ... }: + +with pkgs.vimPlugins; +[ + { plugin = luasnip; + config = '' + lua << EOF + local luasnip = require 'luasnip' + + -- Expand or jump in a snippet + vim.api.nvim_set_keymap('i', '', 'lua return luasnip.expand_or_jumpable() and \'luasnip-expand-or-jump\' or \'\'', { expr = true, silent = true }) + + -- Jump backwards in a snippet + vim.api.nvim_set_keymap('i', '', 'lua luasnip.jump(-1)', {silent = true}) + + -- Keymaps for Select mode + vim.api.nvim_set_keymap('s', '', 'lua require(\'luasnip\').jump(1)', {silent = true}) + vim.api.nvim_set_keymap('s', '', 'lua require(\'luasnip\').jump(-1)', {silent = true}) + + -- Changing choices in choiceNodes + vim.api.nvim_set_keymap('i', '', 'lua return luasnip.choice_active() and \'luasnip-next-choice\' or \'\'', { expr = true, silent = true }) + vim.api.nvim_set_keymap('s', '', 'lua return luasnip.choice_active() and \'luasnip-next-choice\' or \'\'', { expr = true, silent = true }) + EOF + ''; + } +] diff --git a/homeConfig/modules/neovim/config/plugins/theme/default.nix b/homeConfig/modules/neovim/config/plugins/theme/default.nix new file mode 100644 index 0000000..775821d --- /dev/null +++ b/homeConfig/modules/neovim/config/plugins/theme/default.nix @@ -0,0 +1,56 @@ +{ pkgs, lib, ... }: + +let + + panvimdoc = pkgs.fetchFromGitHub { + owner = "kdheepak"; + repo = "panvimdoc"; + rev = "v3.0.6"; + sha256 = "0smij72mpd1lm6akjzkmh2z76xfgn86n7n1ah36fz16p1krc1nwv"; + }; + github-theme = pkgs.stdenv.mkDerivation { + pname = "github-theme"; + version = "1.0.0"; + src = pkgs.fetchFromGitHub { + owner = "projekt0n"; + repo = "github-nvim-theme"; + rev = "v1.0.0"; + sha256 = "1b9fac3ajqr9i5291k3z3pgrh3l08ga1ghdw05s1nq3xvbzcicn5"; + }; + buildInputs = [ pkgs.makeWrapper ]; + + buildPhase = '' + # replace misc/panvimdoc with our pre-fetched version + rm -rf misc/panvimdoc + ln -s ${panvimdoc} misc/panvimdoc + + # carry on with the build as normal + make + ''; + + installPhase = '' + # install the plugin to $out + mkdir -p $out + cp -r * $out + ''; + + meta = with lib; { + description = "A dark theme for Neovim"; + homepage = "https://github.com/projekt0n/github-nvim-theme"; + license = licenses.mit; + platforms = platforms.all; + }; + }; + +in +[ + { + plugin = github-theme; + config = '' + lua << EOF + vim.cmd('colorscheme github_dark_high_contrast') + EOF + ''; + } +] + diff --git a/homeConfig/modules/neovim/config/plugins/tools/default.nix b/homeConfig/modules/neovim/config/plugins/tools/default.nix new file mode 100644 index 0000000..c9fbe7d --- /dev/null +++ b/homeConfig/modules/neovim/config/plugins/tools/default.nix @@ -0,0 +1,9 @@ + { pkgs, ... }: + +with pkgs.vimPlugins; +[ + { plugin = lazygit-nvim; } + { plugin = nvim-web-devicons; } + { plugin = lualine-nvim; } + { plugin = neo-tree-nvim; } +] diff --git a/homeConfig/modules/neovim/config/plugins/treesitter/default.nix b/homeConfig/modules/neovim/config/plugins/treesitter/default.nix new file mode 100644 index 0000000..f550aa8 --- /dev/null +++ b/homeConfig/modules/neovim/config/plugins/treesitter/default.nix @@ -0,0 +1,17 @@ +{ pkgs, ...}: + +with pkgs.vimPlugins; + +[ + { plugin = nvim-treesitter.withAllGrammars; + config = '' + lua << EOF + require'nvim-treesitter.configs'.setup { + highlight = { + enable = true, + }, + } + EOF + ''; + } +] diff --git a/homeConfig/modules/neovim/config/lsp.nix b/homeConfig/modules/neovim/config/servers.nix similarity index 100% rename from homeConfig/modules/neovim/config/lsp.nix rename to homeConfig/modules/neovim/config/servers.nix diff --git a/homeConfig/modules/neovim/default.nix b/homeConfig/modules/neovim/default.nix index f3dc025..12387ac 100644 --- a/homeConfig/modules/neovim/default.nix +++ b/homeConfig/modules/neovim/default.nix @@ -12,9 +12,9 @@ in viAlias = true; vimAlias = true; -# extraLuaConfig = import ./config/init.nix; - plugins = import ./config/plugins.nix { inherit pkgs; }; - extraPackages = import ./config/lsp.nix { inherit pkgs; }; + extraLuaConfig = import ./config/init.nix; + plugins = import (./config/plugins) { inherit pkgs lib; }; + extraPackages = import ./config/servers.nix { inherit pkgs; }; }; }; }