From b19f90dc7fac37f48405f7e8ae2441406cb448e9 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Sat, 13 Apr 2024 05:38:25 +0200 Subject: [PATCH] Changed a couple of nvim settings, added some keybinds, disabled treej, and added conform.nvim --- nvim/dot-config/nvim/init.lua | 1002 ++++++++++-------- nvim/dot-config/nvim/lazy-lock.json | 2 +- nvim/dot-config/nvim/lua/options.lua | 12 +- nvim/dot-config/nvim/lua/plugins/conform.lua | 63 ++ nvim/dot-config/nvim/lua/plugins/treesj.lua | 1 + 5 files changed, 605 insertions(+), 475 deletions(-) create mode 100644 nvim/dot-config/nvim/lua/plugins/conform.lua diff --git a/nvim/dot-config/nvim/init.lua b/nvim/dot-config/nvim/init.lua index b8d5dac..37f747b 100644 --- a/nvim/dot-config/nvim/init.lua +++ b/nvim/dot-config/nvim/init.lua @@ -38,436 +38,497 @@ P.S. You can delete this when you're done too. It's your config now :) -- Set as the leader key -- See `:help mapleader` -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' +vim.g.mapleader = " " +vim.g.maplocalleader = " " -- Install package manager -- https://github.com/folke/lazy.nvim -- `:help lazy.nvim.txt` for more info -local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +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, - } + 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) -local symbols = require('constant.symbols'); -local border = 'rounded'; +local symbols = require("constant.symbols") +local border = "rounded" + +-- Helper function for staging selection +local function gitsigns_visual_op(op) + return function() + return require("gitsigns")[op]({ vim.fn.line("."), vim.fn.line("v") }) + end +end -- NOTE: Here is where you install your plugins. -- You can configure plugins using the `config` key. -- -- You can also configure plugins after the setup call, -- as they will be available in your neovim runtime. -require('lazy').setup({ +require("lazy").setup({ - -- NOTE: This is where your plugins related to LSP can be installed. - -- The configuration is done below. Search for lspconfig to find it below. - { - -- LSP Configuration & Plugins - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs to stdpath for neovim - 'williamboman/mason.nvim', - 'williamboman/mason-lspconfig.nvim', + -- NOTE: This is where your plugins related to LSP can be installed. + -- The configuration is done below. Search for lspconfig to find it below. + { + -- LSP Configuration & Plugins + "neovim/nvim-lspconfig", + dependencies = { + -- Automatically install LSPs to stdpath for neovim + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", - -- Useful status updates for LSP - -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', opts = {} }, + -- Useful status updates for LSP + -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` + { "j-hui/fidget.nvim", opts = {} }, - -- Additional lua configuration, makes nvim stuff amazing! - 'folke/neodev.nvim', + -- Additional lua configuration, makes nvim stuff amazing! + "folke/neodev.nvim", - -- Add document color - 'mrshmllow/document-color.nvim', + -- Add document color + "mrshmllow/document-color.nvim", - 'b0o/schemastore.nvim', + "b0o/schemastore.nvim", - -- Rename with immediate visual feedback - { - 'smjonas/inc-rename.nvim', - config = function() - require('inc_rename').setup { - preview_empty_name = true, - } - end - }, - }, - }, + -- Rename with immediate visual feedback + { + "smjonas/inc-rename.nvim", + config = function() + require("inc_rename").setup({ + preview_empty_name = true, + }) + end, + }, + }, + }, - { - 'ray-x/lsp_signature.nvim', - dependencies = { - 'neovim/nvim-lspconfig', - }, - opts = { - hint_enable = false, - handler_opts = { - border = border - } - }, - }, + { + "ray-x/lsp_signature.nvim", + dependencies = { + "neovim/nvim-lspconfig", + }, + opts = { + hint_enable = false, + handler_opts = { + border = border, + }, + }, + }, - { - -- Autocompletion - 'hrsh7th/nvim-cmp', - dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', 'hrsh7th/cmp-path', - 'onsails/lspkind-nvim', }, - }, + { + -- Autocompletion + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-nvim-lsp", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-path", + "onsails/lspkind-nvim", + }, + }, - -- Useful plugin to show you pending keybinds. - { 'folke/which-key.nvim', opts = {} }, - { - -- Adds git releated signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - init = function() - vim.keymap.set('n', 'gs', require('gitsigns.actions').stage_hunk, { desc = "[G]it [S]tage hunk" }) - vim.keymap.set('n', 'gS', require('gitsigns.actions').undo_stage_hunk, { desc = "[G]it undo [S]tage hunk" }) - vim.keymap.set('n', 'gd', require('gitsigns.actions').preview_hunk_inline, { desc = "[G]it [D]iff hunk " }) - vim.keymap.set('n', ']g', require('gitsigns.actions').next_hunk, { desc = "Go to next hunk" }) - vim.keymap.set('n', '[g', require('gitsigns.actions').prev_hunk, { desc = "Go to previous hunk" }) - end, - opts = { - -- See `:help gitsigns.txt` - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - }, - }, + -- Useful plugin to show you pending keybinds. + { + "folke/which-key.nvim", + opts = {}, + init = function() + require("which-key").register({ + ["g"] = { name = "[G]it", _ = "which_key_ignore" }, + ["b"] = { name = "[B]buffer", _ = "which_key_ignore" }, + ["s"] = { name = "[S]earch", _ = "which_key_ignore" }, + }) + end, + }, + { + -- Adds git related signs to the gutter, as well as utilities for managing changes + "lewis6991/gitsigns.nvim", + init = function() + vim.keymap.set("n", "gs", require("gitsigns.actions").stage_hunk, { desc = "[G]it [S]tage hunk" }) + vim.keymap.set( + "n", + "gS", + require("gitsigns.actions").undo_stage_hunk, + { desc = "[G]it undo [S]tage hunk" } + ) + vim.keymap.set( + "n", + "gd", + require("gitsigns.actions").preview_hunk_inline, + { desc = "[G]it [D]iff hunk" } + ) + vim.keymap.set("n", "gr", require("gitsigns.actions").reset_hunk, { desc = "[G]it [R]eset hunk" }) + vim.keymap.set("v", "gs", gitsigns_visual_op("stage_hunk"), { desc = "[G]it [S]tage selection" }) + vim.keymap.set("v", "gr", gitsigns_visual_op("reset_hunk"), { desc = "[G]it [R]eset selection" }) + vim.keymap.set("n", "]g", function() + require("gitsigns.actions").nav_hunk("next") + end, { desc = "Go to next hunk" }) + vim.keymap.set("n", "[g", function() + require("gitsigns.actions").nav_hunk("prev") + end, { desc = "Go to previous hunk" }) + end, + opts = { + -- See `:help gitsigns.txt` + signs = { + add = { text = "+" }, + change = { text = "~" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + }, + }, + }, - { - -- Set lualine as statusline - 'nvim-lualine/lualine.nvim', - -- See `:help lualine.txt` - opts = { - options = { - icons_enabled = true, - theme = 'gruvbox', - component_separators = { left = '', right = '' }, - section_separators = { left = '', right = '' }, - }, - sections = { - lualine_b = { - 'branch', - 'diff', - { 'diagnostics', symbols = { error = '', warn = '', info = '', hint = '' } }, - }, - lualine_c = { - { - 'filename', - path = 1, - symbols = { - modified = symbols.file.modified, - readonly = symbols.file.readonly, - } - }, - }, - lualine_x = { - 'encoding', { 'fileformat', icons_enabled = false }, 'filetype', - }, - }, - inactive_sections = { - lualine_c = { - { 'filename', path = 1 }, - }, - }, - }, - }, + { + -- Set lualine as statusline + "nvim-lualine/lualine.nvim", + -- See `:help lualine.txt` + opts = { + options = { + icons_enabled = true, + theme = "gruvbox", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + }, + sections = { + lualine_b = { + "branch", + "diff", + { "diagnostics", symbols = { error = "", warn = "", info = "", hint = "" } }, + }, + lualine_c = { + { + "filename", + path = 1, + symbols = { + modified = symbols.file.modified, + readonly = symbols.file.readonly, + }, + }, + }, + lualine_x = { + "encoding", + { "fileformat", icons_enabled = false }, + "filetype", + }, + }, + inactive_sections = { + lualine_c = { + { "filename", path = 1 }, + }, + }, + }, + }, - { - -- Add indentation guides even on blank lines - 'lukas-reineke/indent-blankline.nvim', - -- Enable `lukas-reineke/indent-blankline.nvim` - -- See `:help indent_blankline.txt` - main = "ibl", - opts = { - indent = { - char = '¦', - }, - }, - }, + { + -- Add indentation guides even on blank lines + "lukas-reineke/indent-blankline.nvim", + -- Enable `lukas-reineke/indent-blankline.nvim` + -- See `:help indent_blankline.txt` + main = "ibl", + opts = { + indent = { + char = "¦", + }, + }, + }, + -- Fuzzy Finder (files, lsp, etc) + { + "nvim-telescope/telescope.nvim", + version = "*", + dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope-ui-select.nvim" }, + }, - -- Fuzzy Finder (files, lsp, etc) - { - 'nvim-telescope/telescope.nvim', - version = '*', - dependencies = { 'nvim-lua/plenary.nvim', - 'nvim-telescope/telescope-ui-select.nvim' } - }, + -- Fuzzy Finder Algorithm which requires local dependencies to be built. + -- Only load if `make` is available. Make sure you have the system + -- requirements installed. + { + "nvim-telescope/telescope-fzf-native.nvim", + -- NOTE: If you are having trouble with this installation, + -- refer to the README for telescope-fzf-native for more instructions. + build = "make", + cond = function() + return vim.fn.executable("make") == 1 + end, + }, - -- Fuzzy Finder Algorithm which requires local dependencies to be built. - -- Only load if `make` is available. Make sure you have the system - -- requirements installed. - { - 'nvim-telescope/telescope-fzf-native.nvim', - -- NOTE: If you are having trouble with this installation, - -- refer to the README for telescope-fzf-native for more instructions. - build = 'make', - cond = function() - return vim.fn.executable 'make' == 1 - end, - }, + { + -- Highlight, edit, and navigate code + "nvim-treesitter/nvim-treesitter", + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + "nvim-treesitter/nvim-treesitter-context", + }, + config = function() + pcall(require("nvim-treesitter.install").update({ with_sync = true })) + end, + }, - { - -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - 'nvim-treesitter/nvim-treesitter-context', - }, - config = function() - pcall(require('nvim-treesitter.install').update { with_sync = true }) - end, - }, - - require 'themes.gruvbox', - { import = 'plugins' }, + require("themes.gruvbox"), + { import = "plugins" }, }, { - install = { - colorscheme = { - 'gruvbox', - } - } + install = { + colorscheme = { + "gruvbox", + }, + }, }) -require('options') -require('keymaps') -require('autocmds') +require("options") +require("keymaps") +require("autocmds") -- [[ Configure Telescope ]] -- See `:help telescope` and `:help telescope.setup()` -require('telescope').setup { - pickers = { - find_files = { - hidden = true, - }, - }, - defaults = { - file_ignore_patterns = { - ".git/", - }, - mappings = { - n = { - [''] = "delete_buffer", - [''] = "move_selection_next", - [''] = "move_selection_previous", - }, - i = { - [''] = "delete_buffer", - [''] = "move_selection_next", - [''] = "move_selection_previous", - }, - }, - }, - extensions = { - ["ui-select"] = { - require('telescope.themes').get_dropdown {} - } - } -} +require("telescope").setup({ + pickers = { + find_files = { + hidden = true, + }, + }, + defaults = { + file_ignore_patterns = { + ".git/", + }, + mappings = { + n = { + [""] = "delete_buffer", + [""] = "move_selection_next", + [""] = "move_selection_previous", + }, + i = { + [""] = "delete_buffer", + [""] = "move_selection_next", + [""] = "move_selection_previous", + }, + }, + }, + extensions = { + ["ui-select"] = { + require("telescope.themes").get_dropdown({}), + }, + }, +}) -- Enable telescope fzf native, if installed -pcall(require('telescope').load_extension, 'fzf') -pcall(require('telescope').load_extension, 'ui-select') +pcall(require("telescope").load_extension, "fzf") +pcall(require("telescope").load_extension, "ui-select") -- See `:help telescope.builtin` -vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) -vim.keymap.set('n', '', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' }) -vim.keymap.set('n', '/', function() - require('telescope.builtin').current_buffer_fuzzy_find({ - -- Show matches in the order they appear in the document - sorting_strategy = "ascending", - }) -end, { desc = '[/] Fuzzily search in current buffer' }) +vim.keymap.set("n", ".", require("telescope.builtin").oldfiles, { desc = "[.] Find recently opened files" }) +vim.keymap.set("n", "", require("telescope.builtin").buffers, { desc = "[ ] Find existing buffers" }) +vim.keymap.set("n", "/", function() + require("telescope.builtin").current_buffer_fuzzy_find({ + -- Show matches in the order they appear in the document + sorting_strategy = "ascending", + }) +end, { desc = "[/] Fuzzily search in current buffer" }) +vim.keymap.set("n", "s/", function() + require("telescope.builtin").live_grep({ + grep_open_files = true, + prompt_title = "Live Grep in Open Files", + }) +end, { desc = "[S]earch [/] in Open Files" }) -vim.keymap.set('n', 'sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) -vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) -vim.keymap.set('n', 'sw', function() - require('telescope.builtin').grep_string({ - -- Show matches in the order they appear in the document - sorting_strategy = "ascending", - }) -end, { desc = '[S]earch current [W]ord' }) -vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) -vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) -vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) +vim.keymap.set("n", "sf", require("telescope.builtin").find_files, { desc = "[S]earch [F]iles" }) +vim.keymap.set("n", "sh", require("telescope.builtin").help_tags, { desc = "[S]earch [H]elp" }) +vim.keymap.set("n", "sw", function() + require("telescope.builtin").grep_string({ + -- Show matches in the order they appear in the document + sorting_strategy = "ascending", + }) +end, { desc = "[S]earch current [W]ord" }) +vim.keymap.set("n", "sg", require("telescope.builtin").live_grep, { desc = "[S]earch by [G]rep" }) +vim.keymap.set("n", "sd", require("telescope.builtin").diagnostics, { desc = "[S]earch [D]iagnostics" }) +vim.keymap.set("n", "sr", require("telescope.builtin").resume, { desc = "[S]earch [R]esume" }) +vim.keymap.set("n", "sk", require("telescope.builtin").keymaps, { desc = "[S]earch [K]eymaps" }) +vim.keymap.set("n", "sn", function() + require("telescope.builtin").find_files({ cwd = vim.fn.stdpath("config") }) +end, { desc = "[S]earch [N]eovim files" }) -- [[ Configure Treesitter ]] -- See `:help nvim-treesitter` -require('nvim-treesitter.configs').setup { - -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim', 'markdown', - 'markdown_inline', 'bash', 'zig' }, +require("nvim-treesitter.configs").setup({ + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { + "c", + "cpp", + "go", + "lua", + "python", + "rust", + "tsx", + "typescript", + "vimdoc", + "vim", + "markdown", + "markdown_inline", + "bash", + "zig", + }, - -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) - auto_install = true, + -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) + auto_install = true, - highlight = { enable = true }, - -- Disabled because it caueses issues with nvim-autopair - indent = { enable = false, disable = { 'python' } }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', - }, - }, - textobjects = { - select = { - enable = true, - lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim - keymaps = { - -- You can use the capture groups defined in textobjects.scm - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@class.outer', - ['ic'] = '@class.inner', - }, - }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - [']m'] = '@function.outer', - [']]'] = '@class.outer', - }, - goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', - }, - goto_previous_start = { - ['[m'] = '@function.outer', - ['[['] = '@class.outer', - }, - goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', - }, - }, - swap = { - enable = true, - swap_next = { - ['a'] = '@parameter.inner', - }, - swap_previous = { - ['A'] = '@parameter.inner', - }, - }, - }, -} + highlight = { enable = true }, + -- Disabled because it caueses issues with nvim-autopair + indent = { enable = false, disable = { "python" } }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "", + node_incremental = "", + scope_incremental = "", + node_decremental = "", + }, + }, + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["aa"] = "@parameter.outer", + ["ia"] = "@parameter.inner", + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]m"] = "@function.outer", + ["]]"] = "@class.outer", + }, + goto_next_end = { + ["]M"] = "@function.outer", + ["]["] = "@class.outer", + }, + goto_previous_start = { + ["[m"] = "@function.outer", + ["[["] = "@class.outer", + }, + goto_previous_end = { + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", + }, + }, + swap = { + enable = true, + swap_next = { + ["a"] = "@parameter.inner", + }, + swap_previous = { + ["A"] = "@parameter.inner", + }, + }, + }, +}) -- LSP settings. -vim.lsp.handlers['textDocument/hover'] = vim.lsp.with( - vim.lsp.handlers.hover, - { border = border } -) +vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }) -vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with( - vim.lsp.handlers.hover, - { border = border } -) +vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border }) -vim.diagnostic.config { - float = { - border = border - } -} +vim.diagnostic.config({ + float = { + border = border, + }, +}) -- Set the diagnostic symbols (Also used by Neo-tree) local signs = { - Error = symbols.diagnostic.error, - Warn = symbols.diagnostic.warning, - Hint = symbols.diagnostic.hint, - Info = symbols.diagnostic.info + Error = symbols.diagnostic.error, + Warn = symbols.diagnostic.warning, + Hint = symbols.diagnostic.hint, + Info = symbols.diagnostic.info, } for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end -- This function gets run when an LSP connects to a particular buffer. local on_attach = function(client, bufnr) - -- NOTE: Remember that lua is a real programming language, and as such it is possible - -- to define small helper and utility functions so you don't have to repeat yourself - -- many times. - -- - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. - local nmap = function(keys, func, desc) - if desc then - desc = 'LSP: ' .. desc - end + -- NOTE: Remember that lua is a real programming language, and as such it is possible + -- to define small helper and utility functions so you don't have to repeat yourself + -- many times. + -- + -- In this case, we create a function that lets us more easily define mappings specific + -- for LSP related items. It sets the mode, buffer and description for us each time. + local nmap = function(keys, func, desc) + if desc then + desc = "LSP: " .. desc + end - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) - end + vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc }) + end - vim.keymap.set('n', 'rn', function() - return ':IncRename ' .. vim.fn.expand('') - end, { expr = true, desc = '[R]e[n]ame' }) + vim.keymap.set("n", "rn", function() + return ":IncRename " .. vim.fn.expand("") + end, { expr = true, desc = "[R]e[n]ame" }) - -- nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') - -- Should allow code actions in visual mode - vim.keymap.set({ 'v', 'n' }, 'ca', vim.lsp.buf.code_action, - { buffer = bufnr, desc = 'LSP: [C]ode [A]ction', remap = true }) - -- nmap('ca', require('telescope.builtin')., '[C]ode [A]ction') + -- nmap('ca', vim.lsp.buf.code_action, '[C]ode [A]ction') + -- Should allow code actions in visual mode + vim.keymap.set( + { "v", "n" }, + "ca", + vim.lsp.buf.code_action, + { buffer = bufnr, desc = "LSP: [C]ode [A]ction", remap = true } + ) + -- nmap('ca', require('telescope.builtin')., '[C]ode [A]ction') - nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition') - nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') - nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation') - nmap('D', vim.lsp.buf.type_definition, 'Type [D]efinition') - nmap('ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols') - nmap('ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols') + nmap("gd", vim.lsp.buf.definition, "[G]oto [D]efinition") + nmap("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") + nmap("gI", vim.lsp.buf.implementation, "[G]oto [I]mplementation") + nmap("D", vim.lsp.buf.type_definition, "Type [D]efinition") + nmap("ds", require("telescope.builtin").lsp_document_symbols, "[D]ocument [S]symbols") + nmap("ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]symbols") - -- See `:help K` for why this keymap - nmap('K', vim.lsp.buf.hover, 'Hover Documentation') - nmap('', vim.lsp.buf.signature_help, 'Signature Documentation') + -- See `:help K` for why this keymap + nmap("K", vim.lsp.buf.hover, "Hover Documentation") + nmap("", vim.lsp.buf.signature_help, "Signature Documentation") - -- Lesser used LSP functionality - nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration') - nmap('wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder') - nmap('wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder') - nmap('wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, '[W]orkspace [L]ist Folders') + -- Lesser used LSP functionality + nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") + nmap("wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") + nmap("wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") + nmap("wl", function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, "[W]orkspace [L]ist Folders") - -- Create a command `:Format` local to the LSP buffer - vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) - vim.lsp.buf.format() - end, { desc = 'Format current buffer with LSP' }) - - -- Format on save - local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) - if client.supports_method("textDocument/formatting") then - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.format() - end, - }) - end - - -- Attach document colour support - if client.server_capabilities.colorProvider then - require("document-color").buf_attach(bufnr) - end + -- -- Create a command `:Format` local to the LSP buffer + -- vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_) + -- vim.lsp.buf.format() + -- end, { desc = 'Format current buffer with LSP' }) + -- + -- -- Format on save + -- local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + -- if client.supports_method("textDocument/formatting") then + -- vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + -- vim.api.nvim_create_autocmd("BufWritePre", { + -- group = augroup, + -- buffer = bufnr, + -- callback = function() + -- vim.lsp.buf.format() + -- end, + -- }) + -- end + -- + -- -- Attach document colour support + -- if client.server_capabilities.colorProvider then + -- require("document-color").buf_attach(bufnr) + -- end end -- Enable the following language servers @@ -476,132 +537,131 @@ end -- Add any additional override configuration in the following tables. They will be passed to -- the `settings` field of the server config. You must look up that documentation yourself. local servers = { - clangd = {}, - gopls = {}, - pyright = {}, - zls = {}, - rust_analyzer = { - -- enable clippy on save - ["rust-analyzer"] = { - checkOnSave = { - command = "clippy", - }, - check = { - allTargets = false, - }, - }, - }, - tsserver = {}, - tailwindcss = {}, - -- cssls = {}, + clangd = {}, + gopls = {}, + pyright = {}, + rust_analyzer = { + -- enable clippy on save + ["rust-analyzer"] = { + checkOnSave = { + command = "clippy", + }, + check = { + allTargets = false, + }, + }, + }, + tsserver = {}, + tailwindcss = {}, + -- cssls = {}, - lua_ls = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, - }, - }, - jsonls = { - json = { - schemas = require('schemastore').json.schemas(), - }, - }, - yamlls = { - yaml = { - schemas = require('schemastore').yaml.schemas(), - }, - }, - taplo = {}, - cmake = {} + lua_ls = { + Lua = { + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, + }, + }, + jsonls = { + json = { + schemas = require("schemastore").json.schemas(), + }, + }, + yamlls = { + yaml = { + schemas = require("schemastore").yaml.schemas(), + }, + }, + taplo = {}, + cmake = {}, } -- Setup neovim lua configuration -require('neodev').setup() +require("neodev").setup() -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) +capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) capabilities.textDocument.colorProvider = { - dynamicRegistration = true + dynamicRegistration = true, } -- Setup mason so it can manage external tooling -require('mason').setup() +require("mason").setup() -- Ensure the servers above are installed -local mason_lspconfig = require 'mason-lspconfig' +local mason_lspconfig = require("mason-lspconfig") -mason_lspconfig.setup { - ensure_installed = vim.tbl_keys(servers), -} +mason_lspconfig.setup({ + ensure_installed = vim.tbl_keys(servers), +}) -mason_lspconfig.setup_handlers { - function(server_name) - require('lspconfig')[server_name].setup { - capabilities = capabilities, - on_attach = on_attach, - settings = servers[server_name], - } - end, -} +mason_lspconfig.setup_handlers({ + function(server_name) + require("lspconfig")[server_name].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = servers[server_name], + }) + end, +}) -- nvim-cmp setup -local cmp = require 'cmp' -local luasnip = require 'luasnip' -local lspkind = require 'lspkind' +local cmp = require("cmp") +local luasnip = require("luasnip") +local lspkind = require("lspkind") -luasnip.config.setup {} +luasnip.config.setup({}) -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) - end, - }, - -- Include the source of the cmp entry - formatting = { - format = lspkind.cmp_format({ - mode = "text", - menu = { - nvim_lsp = "[LSP]", - luasnip = "[LuaSnip]", - path = "[Path]", - }, - }), - }, - mapping = cmp.mapping.preset.insert { - [''] = 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_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 = 'luasnip' }, - { name = 'nvim_lsp' }, - { name = 'path' }, - }, -} +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + -- Include the source of the cmp entry + formatting = { + format = lspkind.cmp_format({ + mode = "text", + menu = { + nvim_lsp = "[LSP]", + luasnip = "[LuaSnip]", + path = "[Path]", + }, + }), + }, + mapping = cmp.mapping.preset.insert({ + [""] = 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_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 = "luasnip" }, + { name = "nvim_lsp" }, + { name = "path" }, + }, +}) -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et diff --git a/nvim/dot-config/nvim/lazy-lock.json b/nvim/dot-config/nvim/lazy-lock.json index 9a0524a..fe45830 100644 --- a/nvim/dot-config/nvim/lazy-lock.json +++ b/nvim/dot-config/nvim/lazy-lock.json @@ -5,6 +5,7 @@ "cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "conform.nvim": { "branch": "master", "commit": "9d5ba06d6ee7418c674f498634617416d15b6239" }, "document-color.nvim": { "branch": "main", "commit": "74c487f0e5accfaae033755451b9e367220693fd" }, "fidget.nvim": { "branch": "main", "commit": "1ba38e4cbb24683973e00c2e36f53ae64da38ef5" }, "gitsigns.nvim": { "branch": "main", "commit": "c097cb255096f333e14d341082a84f572b394fa2" }, @@ -40,7 +41,6 @@ "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, "todo-comments.nvim": { "branch": "main", "commit": "a736bbe08c8eff370dfa60701f1e669816d4e3c8" }, - "treesj": { "branch": "main", "commit": "60e27280030f9cd8dfb6ceb335922c6ff76682cc" }, "trouble.nvim": { "branch": "main", "commit": "b9cf677f20bb2faa2dacfa870b084e568dca9572" }, "undotree": { "branch": "master", "commit": "aa93a7e5890dbbebbc064cd22260721a6db1a196" }, "which-key.nvim": { "branch": "main", "commit": "4433e5ec9a507e5097571ed55c02ea9658fb268a" }, diff --git a/nvim/dot-config/nvim/lua/options.lua b/nvim/dot-config/nvim/lua/options.lua index 4b03cac..478d5e9 100644 --- a/nvim/dot-config/nvim/lua/options.lua +++ b/nvim/dot-config/nvim/lua/options.lua @@ -1,6 +1,6 @@ --- See `:help vim.o` --- Set highlight on search -vim.o.hlsearch = false +-- Set highlight on search, clear by pressing esc +vim.o.hlsearch = true +vim.keymap.set('n', '', 'nohlsearch') -- Make line numbers default vim.wo.number = true @@ -52,3 +52,9 @@ vim.o.confirm = true -- Turn on cursorline vim.o.cursorline = true + +-- Don't show mode, powerline already shows it +vim.o.showmode = false + +-- Minimum number of screen lines above and below the cursor +vim.o.scrolloff = 10 diff --git a/nvim/dot-config/nvim/lua/plugins/conform.lua b/nvim/dot-config/nvim/lua/plugins/conform.lua new file mode 100644 index 0000000..fab89d4 --- /dev/null +++ b/nvim/dot-config/nvim/lua/plugins/conform.lua @@ -0,0 +1,63 @@ +-- https://github.com/stevearc/conform.nvim +return { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { + -- Customize or remove this keymap to your liking + "f", + function() + require("conform").format({ async = true, lsp_fallback = true }) + end, + mode = "", + desc = "[F]ormat buffer", + }, + }, + opts = { + -- TODO: Automate installing these using e.g. mason + formatters_by_ft = { + c = { "clang-format" }, + cpp = { "clang-format" }, + go = { "goimports", "gofmt" }, + python = { "ruff_format" }, + rust = { "rustfmt" }, + javascript = { { "prettierd", "prettier" } }, + typescript = { { "prettierd", "prettier" } }, + typescriptreact = { { "prettierd", "prettier" } }, + css = { { "prettierd", "prettier" } }, + markdown = { { "prettierd", "prettier" } }, + lua = { "stylua" }, + json = { "jq" }, + yaml = { { "prettierd", "prettier" } }, + toml = { "taplo" }, + cmake = { "cmake_format" }, + -- ["*"] = { "codespell" }, + ["_"] = { "trim_whitespace", "trim_newlines" }, + }, + format_after_save = { + lsp_fallback = true, + }, + notify_on_error = true, + }, + init = function() + vim.api.nvim_create_user_command("FormatDisable", function(args) + if args.bang then + -- FormatDisable! will disable formatting just for this buffer + vim.b.disable_autoformat = true + else + vim.g.disable_autoformat = true + end + end, { + desc = "Disable autoformat-on-save", + bang = true, + }) + vim.api.nvim_create_user_command("FormatEnable", function() + vim.b.disable_autoformat = false + vim.g.disable_autoformat = false + end, { + desc = "Re-enable autoformat-on-save", + }) + vim.o.formatexpr = "v:lua.require'conform'.formatexpr()" + end, +} diff --git a/nvim/dot-config/nvim/lua/plugins/treesj.lua b/nvim/dot-config/nvim/lua/plugins/treesj.lua index 33c6965..a409b86 100644 --- a/nvim/dot-config/nvim/lua/plugins/treesj.lua +++ b/nvim/dot-config/nvim/lua/plugins/treesj.lua @@ -1,5 +1,6 @@ -- https://github.com/Wansmer/treesj return { + enabled = false, 'Wansmer/treesj', keys = { {