From dc4b451540d789cfdeabaf8deda36d967bd46348 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sat, 1 Jun 2024 11:56:27 +0200 Subject: [PATCH] Add current nvim config generated from nixvim --- config/neovim/init.lua | 847 +++++++++++++++++++++++ config/neovim/queries/nix/injections.scm | 1 + 2 files changed, 848 insertions(+) create mode 100644 config/neovim/init.lua create mode 120000 config/neovim/queries/nix/injections.scm diff --git a/config/neovim/init.lua b/config/neovim/init.lua new file mode 100644 index 00000000..3aaaa655 --- /dev/null +++ b/config/neovim/init.lua @@ -0,0 +1,847 @@ +require("catppuccin").setup({}) + +-- Set up globals {{{ +do + local nixvim_globals = { + ["git_messenger_no_default_mappings"] = true, + ["mallocalleader"] = " ", + ["mapleader"] = " ", + ["skip_ts_context_commentstring_module"] = true, + } + + for k, v in pairs(nixvim_globals) do + vim.g[k] = v + end +end +-- }}} + +-- Set up options {{{ +do + local nixvim_options = { + ["autoindent"] = false, + ["backspace"] = { "indent", "eol", "start" }, + ["cindent"] = true, + ["cinkeys"] = "0{,0},0),0],:,!^F,o,O,e", + ["completeopt"] = { "menuone", "noselect", "noinsert" }, + ["cursorline"] = true, + ["encoding"] = "utf-8", + ["expandtab"] = true, + ["fileencoding"] = "utf-8", + ["foldcolumn"] = "0", + ["foldenable"] = true, + ["foldexpr"] = "nvim_treesitter#foldexpr()", + ["foldlevel"] = 99, + ["foldlevelstart"] = 99, + ["foldmethod"] = "expr", + ["formatexpr"] = "v:lua.require'conform'.formatexpr()", + ["grepformat"] = "%f:%l:%c:%m", + ["grepprg"] = "rg --vimgrep", + ["hidden"] = true, + ["hlsearch"] = true, + ["ignorecase"] = true, + ["incsearch"] = true, + ["laststatus"] = 3, + ["mouse"] = "a", + ["number"] = true, + ["pumheight"] = 0, + ["relativenumber"] = true, + ["ruler"] = true, + ["scrolloff"] = 10, + ["shiftwidth"] = 4, + ["showmode"] = false, + ["signcolumn"] = "yes", + ["smartcase"] = true, + ["smartindent"] = false, + ["smarttab"] = true, + ["softtabstop"] = 4, + ["splitbelow"] = true, + ["splitright"] = true, + ["tabstop"] = 4, + ["termguicolors"] = true, + ["timeoutlen"] = 50, + ["undodir"] = "/home/christoph/.vim/undo", + ["undofile"] = true, + } + + for k, v in pairs(nixvim_options) do + vim.opt[k] = v + end +end +-- }}} + +vim.loader.disable() + +vim.cmd([[ + let $BAT_THEME = 'catppuccin' + +colorscheme catppuccin + +]]) +require("yanky").setup({}) + +require("which-key").setup({}) + +require("trim").setup({}) + +require("toggleterm").setup({ + ["auto_scroll"] = true, + ["close_on_exit"] = true, + ["direction"] = "horizontal", + ["float_opts"] = { ["border"] = "curved", ["height"] = 20, ["width"] = 80, ["winblend"] = 0 }, + ["hide_numbers"] = true, + ["insert_mappings"] = true, + ["open_mapping"] = [[]], + ["persist_mode"] = true, + ["shade_terminals"] = true, + ["shell"] = "fish", + ["start_in_insert"] = true, + ["terminal_mappings"] = true, +}) + +require("ufo").setup({}) + +require("colorizer").setup({ + filetypes = nil, + user_default_options = nil, + buftypes = nil, +}) + +require("nvim-autopairs").setup({}) + +vim.notify = require("notify") +require("notify").setup({}) + +local actions = require("nvim-navbuddy.actions") +require("nvim-navbuddy").setup({ ["lsp"] = { ["auto_attach"] = true }, ["window"] = { ["border"] = "rounded" } }) + +require("nvim-lastplace").setup({}) + +require("illuminate").configure({ + ["filetypes_denylist"] = { + "DressingSelect", + "Outline", + "TelescopePrompt", + "alpha", + "harpoon", + "toggleterm", + "neo-tree", + "Spectre", + "reason", + }, +}) + +require("flash").setup({}) + +require("Comment").setup({ + ["mappings"] = { ["basic"] = true, ["extra"] = false }, + ["opleader"] = { ["line"] = "" }, + ["toggler"] = { ["line"] = "" }, +}) + +require("better_escape").setup({ ["mapping"] = { "jk" }, ["timeout"] = 200 }) + +require("noice").setup({ + ["lsp"] = { + ["documentation"] = { + ["opts"] = { + ["border"] = "rounded", + ["format"] = { "{message}" }, + ["lang"] = "markdown", + ["render"] = "plain", + ["replace"] = true, + ["win_options"] = { ["concealcursor"] = "n", ["conceallevel"] = 3 }, + }, + ["view"] = "hover", + }, + ["override"] = { + ["cmp.entry.get_documentation"] = true, + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + }, + }, + ["notify"] = { ["enabled"] = true }, + ["popupmenu"] = { ["backend"] = "nui", ["enabled"] = true }, + ["presets"] = { + ["bottom_search"] = false, + ["command_palette"] = true, + ["inc_rename"] = true, + ["long_message_to_split"] = true, + ["lsp_doc_border"] = true, + }, + ["routes"] = { { ["filter"] = { ["event"] = "msg_show", ["kind"] = "search_count" }, ["opts"] = { ["skip"] = true } } }, +}) + +require("headlines").setup({}) + +require("telescope").setup({ + ["defaults"] = { + ["mappings"] = { ["i"] = { + [""] = function(...) + return require("telescope.actions").close(...) + end, + } }, + }, +}) + +local __telescopeExtensions = { "undo", "ui-select", "fzf" } +for i, extension in ipairs(__telescopeExtensions) do + require("telescope").load_extension(extension) +end + +require("lualine").setup({ + ["extensions"] = { "fzf", "neo-tree", "toggleterm", "trouble" }, + ["options"] = { + ["always_divide_middle"] = true, + ["component_separators"] = { ["left"] = "", ["right"] = "" }, + ["globalstatus"] = true, + ["icons_enabled"] = true, + ["ignore_focus"] = { "neo-tree" }, + ["section_separators"] = { ["left"] = "", ["right"] = "" }, + }, + ["sections"] = { + ["lualine_a"] = { { "mode", ["right_padding"] = "2", ["separator"] = { ["left"] = "" } } }, + ["lualine_b"] = { "branch", "diff", "diagnostics" }, + ["lualine_c"] = { { "filename", ["path"] = 1 } }, + ["lualine_x"] = { "filetype", "encoding", "fileformat" }, + ["lualine_y"] = { "progress", "searchcount", "selectioncount" }, + ["lualine_z"] = { { "location", ["left_padding"] = "2", ["separator"] = { ["right"] = "" } } }, + }, + ["tabline"] = { ["lualine_a"] = { "buffers" }, ["lualine_z"] = { "tabs" } }, +}) +require("luasnip").config.set_config({}) + +require("trouble").setup({}) + +require("inc_rename").setup({}) + +require("conform").setup({ + ["formatters_by_ft"] = { + ["c"] = { "clang-format" }, + ["cpp"] = { "clang-format" }, + ["css"] = { { "prettierd", "prettier" } }, + ["h"] = { "clang-format" }, + ["hpp"] = { "clang-format" }, + ["html"] = { { "prettierd", "prettier" } }, + ["java"] = { "google-java-format" }, + ["javascript"] = { { "prettierd", "prettier" } }, + ["markdown"] = { { "prettierd", "prettier" } }, + ["nix"] = { "alejandra" }, + ["python"] = { "black" }, + ["rust"] = { "rustfmt" }, + }, +}) + +-- LSP {{{ +do + local __lspServers = { + { ["name"] = "texlab" }, + { ["name"] = "tailwindcss" }, + { ["name"] = "rust_analyzer" }, + { ["name"] = "pyright" }, + { ["name"] = "nil_ls" }, + { ["name"] = "marksman" }, + { ["extraOptions"] = { ["autostart"] = true }, ["name"] = "ltex" }, + { + ["extraOptions"] = { + ["cmd"] = { + "/nix/store/c1k19pbnplsnzh9ljcgkyj1p08wb0rdc-vscode-langservers-extracted-4.10.0/bin/vscode-json-language-server", + "--stdio", + }, + }, + ["name"] = "jsonls", + }, + { + ["extraOptions"] = { + ["cmd"] = { + "/nix/store/4ab3m037j0lkzsap5wh7683fdsv8m8na-java-language-server-0.2.46/bin/java-language-server", + }, + }, + ["name"] = "java_language_server", + }, + { + ["extraOptions"] = { + ["cmd"] = { + "/nix/store/c1k19pbnplsnzh9ljcgkyj1p08wb0rdc-vscode-langservers-extracted-4.10.0/bin/vscode-html-language-server", + "--stdio", + }, + }, + ["name"] = "html", + }, + { ["extraOptions"] = { ["cmd"] = { "haskell-language-server-wrapper", "--lsp" } }, ["name"] = "hls" }, + { + ["extraOptions"] = { + ["cmd"] = { + "/nix/store/c1k19pbnplsnzh9ljcgkyj1p08wb0rdc-vscode-langservers-extracted-4.10.0/bin/vscode-eslint-language-server", + "--stdio", + }, + }, + ["name"] = "eslint", + }, + { + ["extraOptions"] = { + ["cmd"] = { + "/nix/store/z8y5rlr53mzh0r0wj00kaprajs1hjib6-dockerfile-language-server-nodejs-0.11.0/bin/docker-langserver", + "--stdio", + }, + }, + ["name"] = "dockerls", + }, + { + ["extraOptions"] = { + ["cmd"] = { + "/nix/store/c1k19pbnplsnzh9ljcgkyj1p08wb0rdc-vscode-langservers-extracted-4.10.0/bin/vscode-css-language-server", + "--stdio", + }, + }, + ["name"] = "cssls", + }, + { ["name"] = "cmake" }, + { ["name"] = "clojure_lsp" }, + { ["name"] = "clangd" }, + } + local __lspOnAttach = function(client, bufnr) end + local __lspCapabilities = function() + capabilities = vim.lsp.protocol.make_client_capabilities() + + capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities()) + + return capabilities + end + + local __setup = { + on_attach = __lspOnAttach, + capabilities = __lspCapabilities(), + } + + for i, server in ipairs(__lspServers) do + if type(server) == "string" then + require("lspconfig")[server].setup(__setup) + else + local options = server.extraOptions + + if options == nil then + options = __setup + else + options = vim.tbl_extend("keep", options, __setup) + end + + require("lspconfig")[server.name].setup(options) + end + end +end +-- }}} + +require("ts_context_commentstring").setup({}) + +require("nvim-treesitter.configs").setup({ + ["highlight"] = { ["enable"] = true }, + ["incremental_selection"] = { + ["enable"] = true, + ["keymaps"] = { + ["init_selection"] = "gnn", + ["node_decremental"] = "grm", + ["node_incremental"] = "grn", + ["scope_incremental"] = "grc", + }, + }, + ["indent"] = { ["enable"] = true }, +}) + +__lint = require("lint") +__lint.linters_by_ft = { + ["c"] = { "clang-tidy" }, + ["clojure"] = { "clj-kondo" }, + ["cpp"] = { "clang-tidy" }, + ["h"] = { "clang-tidy" }, + ["hpp"] = { "clang-tidy" }, + ["java"] = { "checkstyle" }, + ["javascript"] = { "eslint_d" }, + ["markdown"] = { "vale" }, + ["nix"] = { "statix" }, + ["python"] = { "flake8" }, + ["rust"] = { "clippy" }, + ["text"] = { "vale" }, +} + +require("gitsigns").setup({ ["current_line_blame"] = false }) + +require("neo-tree").setup({ + ["buffers"] = { ["bind_to_cwd"] = true, ["follow_current_file"] = { ["enabled"] = true } }, + ["close_if_last_window"] = true, + ["enable_diagnostics"] = true, + ["enable_git_status"] = true, + ["enable_modified_markers"] = true, + ["enable_refresh_on_write"] = true, + ["popup_border_style"] = "rounded", + ["window"] = { ["auto_expand_width"] = false, ["height"] = 15, ["mappings"] = { [""] = "none" }, ["width"] = 40 }, +}) + +local cmp = require("cmp") +cmp.setup({ + ["extraConfigLua"] = '-- local cmp = require(\'cmp\')\n\n-- Use buffer source for `/` (if you enabled `native_menu`, this won\'t work anymore).\n-- cmp.setup.cmdline({\'/\', "?" }, {\n-- sources = {\n-- { name = \'buffer\' }\n-- }\n-- })\n\n-- Set configuration for specific filetype.\n-- cmp.setup.filetype(\'gitcommit\', {\n-- sources = cmp.config.sources({\n-- { name = \'cmp_git\' }, -- You can specify the `cmp_git` source if you were installed it.\n-- }, {\n-- { name = \'buffer\' },\n-- })\n-- })\n\n-- Use cmdline & path source for \':\' (if you enabled `native_menu`, this won\'t work anymore).\n-- cmp.setup.cmdline(\':\', {\n-- sources = cmp.config.sources({\n-- { name = \'path\' }\n-- }, {\n-- { name = \'cmdline\' }\n-- }),\n-- })\n\nkind_icons = {\n Text = "󰊄",\n Method = "",\n Function = "󰡱",\n Constructor = "",\n Field = "",\n Variable = "󱀍",\n Class = "",\n Interface = "",\n Module = "󰕳",\n Property = "",\n Unit = "",\n Value = "",\n Enum = "",\n Keyword = "",\n Snippet = "",\n Color = "",\n File = "",\n Reference = "",\n Folder = "",\n EnumMember = "",\n Constant = "",\n Struct = "",\n Event = "",\n Operator = "",\n TypeParameter = "",\n}\n', + ["mapping"] = cmp.mapping.preset.insert({ + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.abort(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + -- [''] = cmp.complete(), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + if require("luasnip").expandable() then + require("luasnip").expand() + else + cmp.confirm({ select = true }) + end + else + fallback() + end + end), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif require("luasnip").locally_jumpable(1) then + require("luasnip").jump(1) + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require("luasnip").locally_jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end, { "i", "s" }), + }), + ["snippet"] = { + ["expand"] = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + ["sources"] = { + { ["name"] = "async_path" }, + { ["name"] = "emoji" }, + { ["name"] = "nvim_lsp" }, + { ["name"] = "nvim_lsp_signature_help" }, + { ["name"] = "luasnip" }, + }, + ["window"] = { + ["completion"] = { + ["border"] = "rounded", + ["winhighlight"] = "Normal:Normal,FloatBorder:FloatBorder,CursorLine:Visual,Search:None", + }, + ["documentation"] = { ["border"] = "rounded" }, + }, +}) + +require("nvim-navic").setup({ ["click"] = true, ["highlight"] = true }) + +-- Set up keybinds {{{ +do + local __nixvim_binds = { + { ["action"] = require("intellitab").indent, ["key"] = "", ["mode"] = "i" }, + { ["action"] = "", 'v:lua.get_wildmenu_key("", "")', { expr = true }) +vim.api.nvim_set_keymap("c", "", 'v:lua.get_wildmenu_key("", "")', { expr = true }) + +function _G.get_wildmenu_key(key_wildmenu, key_regular) + return vim.fn.wildmenumode() ~= 0 and key_wildmenu or key_regular +end + +-- Set up autogroups {{ +do + local __nixvim_autogroups = { ["nixvim_binds_LspAttach"] = { ["clear"] = true } } + + for group_name, options in pairs(__nixvim_autogroups) do + vim.api.nvim_create_augroup(group_name, options) + end +end +-- }} +-- Set up autocommands {{ +do + local __nixvim_autocommands = { + { + ["callback"] = function() + require("lint").try_lint() + end, + ["event"] = "BufWritePost", + }, + { + ["callback"] = function() + do + local __nixvim_binds = { + { + ["action"] = vim.diagnostic.open_float, + ["key"] = "cD", + ["mode"] = "n", + ["options"] = { ["desc"] = "Show line diagnostic", ["silent"] = false }, + }, + { + ["action"] = vim.lsp.buf.code_action, + ["key"] = "ca", + ["mode"] = "n", + ["options"] = { ["desc"] = "Show code actions", ["silent"] = false }, + }, + { + ["action"] = vim.lsp.buf.rename, + ["key"] = "cr", + ["mode"] = "n", + ["options"] = { ["desc"] = "Rename symbol", ["silent"] = false }, + }, + { + ["action"] = vim.lsp.buf.hover, + ["key"] = "K", + ["mode"] = "n", + ["options"] = { ["desc"] = "Hover information", ["silent"] = false }, + }, + } + for i, map in ipairs(__nixvim_binds) do + vim.keymap.set(map.mode, map.key, map.action, map.options) + end + end + end, + ["desc"] = "Load keymaps for LspAttach", + ["event"] = "LspAttach", + ["group"] = "nixvim_binds_LspAttach", + }, + } + + for _, autocmd in ipairs(__nixvim_autocommands) do + vim.api.nvim_create_autocmd(autocmd.event, { + group = autocmd.group, + pattern = autocmd.pattern, + buffer = autocmd.buffer, + desc = autocmd.desc, + callback = autocmd.callback, + command = autocmd.command, + once = autocmd.once, + nested = autocmd.nested, + }) + end +end +-- }} diff --git a/config/neovim/queries/nix/injections.scm b/config/neovim/queries/nix/injections.scm new file mode 120000 index 00000000..57803157 --- /dev/null +++ b/config/neovim/queries/nix/injections.scm @@ -0,0 +1 @@ +/nix/store/szac9bif2rhcw4q45vbqy4whbcjx2fwb-hm_nvimqueriesnixinjections.scm \ No newline at end of file