diff --git a/home.nix b/home.nix index 28bcd20..a4bdfe8 100644 --- a/home.nix +++ b/home.nix @@ -18,7 +18,6 @@ in packages = with pkgs; [ keepassxc - nil moonlight-qt vlc nicotine-plus @@ -29,9 +28,6 @@ in tree gimp libreoffice - nodePackages.pyright - neofetch - gopls ]; }; @@ -43,26 +39,90 @@ in home-manager.enable = true; chromium.enable = true; - neovim = { + neovim = + let + toLua = str: "lua << EOF\n${str}\nEOF\n"; + toLuaFile = file: "lua << EOF\n${builtins.readFile file}\nEOF\n"; + in + { enable = true; + viAlias = true; vimAlias = true; vimdiffAlias = true; - defaultEditor = true; - plugins = with pkgs.vimPlugins; [ - nvim-lspconfig - gruvbox-nvim - leap-nvim - telescope-nvim - vim-commentary - vim-sleuth - gitsigns-nvim - nvim-cmp - cmp-nvim-lsp - friendly-snippets - neodev-nvim + + extraPackages = with pkgs; [ + luajitPackages.lua-lsp + rnix-lsp + + xclip + wl-clipboard ]; - extraLuaConfig = builtins.readFile ./neovim.lua; + + plugins = with pkgs.vimPlugins; [ + { + plugin = nvim-lspconfig; + config = toLuaFile ./nvim/plugin/lsp.lua; + } + + { + plugin = comment-nvim; + config = toLua "require(\"Comment\").setup()"; + } + + { + plugin = gruvbox-nvim; + config = "colorscheme gruvbox"; + } + + neodev-nvim + + nvim-cmp + { + plugin = nvim-cmp; + config = toLuaFile ./nvim/plugin/cmp.lua; + } + + { + plugin = telescope-nvim; + config = toLuaFile ./nvim/plugin/telescope.lua; + } + + telescope-fzf-native-nvim + + cmp_luasnip + cmp-nvim-lsp + + luasnip + friendly-snippets + + + lualine-nvim + nvim-web-devicons + + { + plugin = (nvim-treesitter.withPlugins (p: [ + p.tree-sitter-nix + p.tree-sitter-vim + p.tree-sitter-bash + p.tree-sitter-lua + p.tree-sitter-python + p.tree-sitter-json + ])); + config = toLuaFile ./nvim/plugin/treesitter.lua; + } + + vim-nix + + # { + # plugin = vimPlugins.own-onedark-nvim; + # config = "colorscheme onedark"; + # } + ]; + + extraLuaConfig = '' + ${builtins.readFile ./nvim/options.lua} + ''; }; alacritty = { diff --git a/neovim.lua b/neovim.lua deleted file mode 100644 index 918c3f2..0000000 --- a/neovim.lua +++ /dev/null @@ -1,124 +0,0 @@ ---[ GLOBAL ]-- - -vim.o.background = "dark" -vim.cmd([[colorscheme gruvbox]]) -vim.g.mapleader = ";" -vim.o.signcolumn = "yes" -vim.wo.number = true -vim.wo.relativenumber = true -vim.wo.cursorline = true - ---[ LSPCONFIG ]-- - -local on_attach = function(_, bufnr) - - local bufmap = function(keys, func) - vim.keymap.set('n', keys, func, { buffer = bufnr }) - end - - bufmap('r', vim.lsp.buf.rename) - bufmap('a', vim.lsp.buf.code_action) - - bufmap('gd', vim.lsp.buf.definition) - bufmap('gD', vim.lsp.buf.declaration) - bufmap('gI', vim.lsp.buf.implementation) - bufmap('D', vim.lsp.buf.type_definition) - - bufmap('gr', require('telescope.builtin').lsp_references) - bufmap('s', require('telescope.builtin').lsp_document_symbols) - bufmap('S', require('telescope.builtin').lsp_dynamic_workspace_symbols) - - bufmap('K', vim.lsp.buf.hover) - - vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) - vim.lsp.buf.format() - end, {}) -end - -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) - -require('neodev').setup() -require'lspconfig'.nil_ls.setup{ on_attach = on_attach, capabilities = capabilities } -require'lspconfig'.pyright.setup{ on_attach = on_attach, capabilities = capabilities } -require'lspconfig'.gopls.setup{ on_attach = on_attach, capabilities = capabilities } - ---[ LEAP ]-- - -require('leap').add_default_mappings() --- Don't remap 'x' in visual mode. -vim.keymap.del({'x', 'o'}, 'x') -vim.keymap.del({'x', 'o'}, 'X') - ---[ TELESCOPE ]-- - -local builtin = require('telescope.builtin') - -vim.keymap.set('n', 'ff', builtin.find_files, {}) -vim.keymap.set('n', 'fg', builtin.live_grep, {}) -vim.keymap.set('n', 'fb', builtin.buffers, {}) -vim.keymap.set('n', 'fr', builtin.lsp_references, {}) -vim.keymap.set('n', 'fs', builtin.lsp_document_symbols, {}) - -require('telescope').setup{ - pickers = { - find_files = { - theme = "dropdown" - }, - live_grep = { - theme = "dropdown" - }, - buffers = { - theme = "dropdown" - }, - lsp_references = { - theme = "dropdown" - }, - lsp_document_symbols = { - theme = "dropdown" - } - } -} - ---[ COMMENTARY ]-- -vim.cmd([[autocmd FileType nix setlocal commentstring=#\ %s]]) - ---[ GITSIGNS ]-- -require("gitsigns").setup() - ---[ CMP ]-- - --- For snippets: look at https://github.com/vimjoyer/nvim-nix-video/blob/main/nvim/plugin/cmp.lua - -local cmp = require('cmp') - -cmp.setup { - mapping = cmp.mapping.preset.insert { - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete {}, - [''] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - else - fallback() - end - end, { 'i', 's' }), - [''] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - else - fallback() - end - end, { 'i', 's' }), - }, - sources = { - { name = 'nvim_lsp' }, - }, -} diff --git a/nvim/options.lua b/nvim/options.lua new file mode 100644 index 0000000..ef6883a --- /dev/null +++ b/nvim/options.lua @@ -0,0 +1,19 @@ + +vim.g.mapleader = ';' +vim.g.maplocalleader = ';' + +vim.o.clipboard = 'unnamedplus' + +vim.o.number = true +-- vim.o.relativenumber = true + +vim.o.signcolumn = 'yes' + +vim.o.tabstop = 4 +vim.o.shiftwidth = 4 + +vim.o.updatetime = 300 + +vim.o.termguicolors = true + +vim.o.mouse = 'a' diff --git a/nvim/plugin/cmp.lua b/nvim/plugin/cmp.lua new file mode 100644 index 0000000..cf2b7a7 --- /dev/null +++ b/nvim/plugin/cmp.lua @@ -0,0 +1,46 @@ +local cmp = require('cmp') +local luasnip = require('luasnip') + +require('luasnip.loaders.from_vscode').lazy_load() +luasnip.config.setup {} + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert { + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = 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_locally_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.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }, + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, +} diff --git a/nvim/plugin/lsp.lua b/nvim/plugin/lsp.lua new file mode 100644 index 0000000..a65c1b2 --- /dev/null +++ b/nvim/plugin/lsp.lua @@ -0,0 +1,48 @@ +local on_attach = function(_, bufnr) + + local bufmap = function(keys, func) + vim.keymap.set('n', keys, func, { buffer = bufnr }) + end + + bufmap('r', vim.lsp.buf.rename) + bufmap('a', vim.lsp.buf.code_action) + + bufmap('gd', vim.lsp.buf.definition) + bufmap('gD', vim.lsp.buf.declaration) + bufmap('gI', vim.lsp.buf.implementation) + bufmap('D', vim.lsp.buf.type_definition) + + bufmap('gr', require('telescope.builtin').lsp_references) + bufmap('s', require('telescope.builtin').lsp_document_symbols) + bufmap('S', require('telescope.builtin').lsp_dynamic_workspace_symbols) + + bufmap('K', vim.lsp.buf.hover) + + vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) + vim.lsp.buf.format() + end, {}) +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) + +require('neodev').setup() +require('lspconfig').lua_ls.setup { + on_attach = on_attach, + capabilities = capabilities, + root_dir = function() + return vim.loop.cwd() + end, + cmd = { "lua-lsp" }, + settings = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + } +} + +require('lspconfig').rnix.setup { + on_attach = on_attach, + capabilities = capabilities, +} diff --git a/nvim/plugin/other.lua b/nvim/plugin/other.lua new file mode 100644 index 0000000..34ff92e --- /dev/null +++ b/nvim/plugin/other.lua @@ -0,0 +1,11 @@ +-- Lualine +require("lualine").setup({ + icons_enabled = true, + theme = 'onedark', +}) + +-- Colorscheme +vim.cmd("colorscheme gruvbox") + +-- Comment +require("Comment").setup() diff --git a/nvim/plugin/telescope.lua b/nvim/plugin/telescope.lua new file mode 100644 index 0000000..59c0ffc --- /dev/null +++ b/nvim/plugin/telescope.lua @@ -0,0 +1,27 @@ +local builtin = require('telescope.builtin') + +vim.keymap.set('n', 'ff', builtin.find_files, {}) +vim.keymap.set('n', 'fg', builtin.live_grep, {}) +vim.keymap.set('n', 'fb', builtin.buffers, {}) +vim.keymap.set('n', 'fr', builtin.lsp_references, {}) +vim.keymap.set('n', 'fs', builtin.lsp_document_symbols, {}) + +require('telescope').setup{ + pickers = { + find_files = { + theme = "dropdown" + }, + live_grep = { + theme = "dropdown" + }, + buffers = { + theme = "dropdown" + }, + lsp_references = { + theme = "dropdown" + }, + lsp_document_symbols = { + theme = "dropdown" + } + } +} diff --git a/nvim/plugin/treesitter.lua b/nvim/plugin/treesitter.lua new file mode 100644 index 0000000..2edb953 --- /dev/null +++ b/nvim/plugin/treesitter.lua @@ -0,0 +1,9 @@ +require('nvim-treesitter.configs').setup { + ensure_installed = {}, + + auto_install = false, + + highlight = { enable = true }, + + indent = { enable = true }, +}