diff --git a/.stylua.toml b/.stylua.toml index 139e9397..ecb6dca5 100644 --- a/.stylua.toml +++ b/.stylua.toml @@ -1,6 +1,6 @@ -column_width = 160 +column_width = 120 line_endings = "Unix" indent_type = "Spaces" indent_width = 2 -quote_style = "AutoPreferSingle" +quote_style = "AutoPreferDouble" call_parentheses = "None" diff --git a/init.lua b/init.lua index 965eec07..2dd74042 100644 --- a/init.lua +++ b/init.lua @@ -1,244 +1,58 @@ -- DISABLED FOR NOW -- @diagnostic disable: missing-fields -- disables annoying warnings --- Lua guides: --- - https://learnxinyminutes.com/docs/lua/ --- - `:help lua-guide` --- - https://neovim.io/doc/user/lua-guide.html --- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) -vim.g.mapleader = ' ' -vim.g.maplocalleader = ' ' - - - -vim.g.have_nerd_font = true - -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 -- ---@diagnostic disable-next-line: undefined-field -vim.opt.runtimepath:prepend(lazypath) - --- 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({ - -- Git related plugins - 'tpope/vim-fugitive', - 'tpope/vim-rhubarb', - - -- Detect tabstop and shiftwidth automatically - 'tpope/vim-sleuth', - - { - -- LSP Configuration & Plugins - 'neovim/nvim-lspconfig', - dependencies = { - -- Automatically install LSPs to stdpath for neovim - { 'williamboman/mason.nvim', config = true }, - 'williamboman/mason-lspconfig.nvim', - - -- Useful status updates for LSP - -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` - { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, - - -- Additional lua configuration, makes nvim stuff amazing! - 'folke/neodev.nvim', - }, - }, - - { - -- Autocompletion - 'hrsh7th/nvim-cmp', - dependencies = { - -- Snippet Engine & its associated nvim-cmp source - 'L3MON4D3/LuaSnip', - 'saadparwaiz1/cmp_luasnip', - - -- Adds LSP completion capabilities - 'hrsh7th/cmp-nvim-lsp', - - -- Adds a number of user-friendly snippets - 'rafamadriz/friendly-snippets', - }, - }, - - -- Useful plugin to show you pending keybinds. - { 'folke/which-key.nvim', opts = {} }, - { - -- Adds git related signs to the gutter, as well as utilities for managing changes - 'lewis6991/gitsigns.nvim', - opts = { - -- See `:help gitsigns.txt` - signs = { - add = { text = '+' }, - change = { text = '~' }, - delete = { text = '_' }, - topdelete = { text = '‾' }, - changedelete = { text = '~' }, - }, - on_attach = function(bufnr) - vim.keymap.set('n', 'hp', require('gitsigns').preview_hunk, - { buffer = bufnr, desc = 'Preview git hunk' }) - - -- don't override the built-in and fugitive keymaps - local gs = package.loaded.gitsigns - vim.keymap.set({ 'n', 'v' }, ']c', function() - if vim.wo.diff then return ']c' end - vim.schedule(function() gs.next_hunk() end) - return '' - end, { expr = true, buffer = bufnr, desc = "Jump to next hunk" }) - vim.keymap.set({ 'n', 'v' }, '[c', function() - if vim.wo.diff then return '[c' end - vim.schedule(function() gs.prev_hunk() end) - return '' - end, { expr = true, buffer = bufnr, desc = "Jump to previous hunk" }) - end, - }, - }, - - { - -- Set lualine as statusline - 'nvim-lualine/lualine.nvim', - -- See `:help lualine.txt` - opts = { - options = { - icons_enabled = false, - theme = 'catppuccin', - component_separators = '|', - section_separators = '', - }, - }, - }, - - { - -- Add indentation guides even on blank lines - 'lukas-reineke/indent-blankline.nvim', - -- Enable `lukas-reineke/indent-blankline.nvim` - -- See `:help indent_blankline.txt` - opts = { - char = '┊', - show_trailing_blankline_indent = false, - }, - }, - - -- "gc" to comment visual regions/lines - { 'numToStr/Comment.nvim', opts = {} }, - - -- Fuzzy Finder (files, lsp, etc) - { - 'nvim-telescope/telescope.nvim', - branch = '0.1.x', - dependencies = { - 'nvim-lua/plenary.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, - }, - }, - }, - - { - -- Highlight, edit, and navigate code - 'nvim-treesitter/nvim-treesitter', - dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects', - }, - build = ':TSUpdate', - }, - - -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart - -- These are some example plugins that I've included in the kickstart repository. - -- Uncomment any of the lines below to enable them. - require 'kickstart.plugins.autoformat', - -- require 'kickstart.plugins.debug', - - -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` - -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping - -- up-to-date with whatever is in the kickstart repo. - -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- - -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins - { import = 'custom.plugins' }, -}, {}) - --- [[ Setting options ]] --- See `:help vim.o` --- NOTE: You can change these options as you wish! +-- [[ Options ]] -- See :help option-list --- Set highlight on search -vim.o.hlsearch = false +-- Must happen before plugins are required +vim.g.mapleader = " " +vim.g.maplocalleader = " " +-- For custom functions later vim.g.have_nerd_font = true --- colorcolumn -vim.o.colorcolumn = "80" +vim.opt.number = true +vim.opt.relativenumber = true --- Make line numbers default -vim.wo.number = true -vim.wo.relativenumber = true +vim.opt.colorcolumn = "80" --- Enable mouse mode -vim.o.mouse = 'a' +-- Only mouse in [h]elp windows +vim.opt.mouse = "h" +-- statusline already shows mode vim.opt.showmode = false --- Sync clipboard between OS and Neovim. --- Remove this option if you want your OS clipboard to remain independent. --- See `:help 'clipboard'` -vim.o.clipboard = 'unnamedplus' --- Enable break indent -vim.o.breakindent = true +-- Copy from anywhere +vim.opt.clipboard = "unnamedplus" --- Save undo history -vim.o.undofile = true +-- Visual wrap keeps indentation +vim.opt.breakindent = true + +vim.opt.undofile = true -- Case-insensitive searching UNLESS \C or capital in search -vim.o.ignorecase = true -vim.o.smartcase = true +vim.opt.ignorecase = true +vim.opt.smartcase = true --- Keep signcolumn on by default -vim.wo.signcolumn = 'yes' +-- Text keeps moving, if not always on +vim.opt.signcolumn = "yes" --- Decrease update time -vim.o.updatetime = 250 -vim.o.timeoutlen = 300 +vim.opt.updatetime = 250 +-- For which-key +vim.opt.timeoutlen = 300 --- Set completeopt to have a better completion experience -vim.o.completeopt = 'menuone,noselect' +vim.opt.list = true +vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" } --- NOTE: You should make sure your terminal supports this -vim.o.termguicolors = true +-- Preview substitutions live, as you type! +vim.opt.inccommand = "split" --- [[ Basic Keymaps ]] +vim.opt.cursorline = true --- Keymaps for better default experience --- See `:help vim.keymap.set()` -vim.keymap.set({ 'n', 'v' }, '', '', { silent = true }) +vim.opt.scrolloff = 10 --- Remap for dealing with word wrap -vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) -vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) -vim.keymap.set('n', 'gk', "v:count == 0 ? 'k' : 'k'", { expr = true, silent = true }) -vim.keymap.set('n', 'gj', "v:count == 0 ? 'j' : 'j'", { expr = true, silent = true }) +vim.opt.splitright = true +vim.opt.splitbelow = true -- wrap between words vim.o.linebreak = true @@ -247,301 +61,600 @@ vim.o.shiftwidth = 4 vim.o.tabstop = 8 vim.o.softtabstop = 4 --- [[ Highlight on yank ]] --- See `:help vim.highlight.on_yank()` -local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) -vim.api.nvim_create_autocmd('TextYankPost', { +-- [[ Basic Keymaps ]] +vim.opt.hlsearch = true +vim.keymap.set("n", "", "nohlsearch") + +vim.keymap.set({ "n", "v" }, "", "", { silent = true }) + +-- Remap for dealing with word wrap +vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) +vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) +vim.keymap.set("n", "gk", "v:count == 0 ? 'k' : 'k'", { expr = true, silent = true }) +vim.keymap.set("n", "gj", "v:count == 0 ? 'j' : 'j'", { expr = true, silent = true }) + +-- Diagnostic keymaps +vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Go to previous [D]iagnostic message" }) +vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Go to next [D]iagnostic message" }) +vim.keymap.set("n", "e", vim.diagnostic.open_float, { desc = "Show diagnostic [E]rror messages" }) +vim.keymap.set("n", "q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" }) + +vim.keymap.set("t", "", "", { desc = "Exit terminal mode" }) + +vim.keymap.set("n", "", "", { desc = "Move focus to the left window" }) +vim.keymap.set("n", "", "", { desc = "Move focus to the right window" }) +vim.keymap.set("n", "", "", { desc = "Move focus to the lower window" }) +vim.keymap.set("n", "", "", { desc = "Move focus to the upper window" }) + +-- [[ Basic Autocommands ]] +-- See ':help lua-guide-autocommands' +vim.api.nvim_create_autocmd("TextYankPost", { + desc = "Highlight when yanking (copying text)", + group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }), callback = function() vim.highlight.on_yank() end, - group = highlight_group, - pattern = '*', }) --- [[ Configure Telescope ]] --- See `:help telescope` and `:help telescope.setup()` -require('telescope').setup { - defaults = { - mappings = { - i = { - [''] = false, - [''] = false, - }, - }, - }, -} - --- Enable telescope fzf native, if installed -pcall(require('telescope').load_extension, 'fzf') - --- 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() - -- You can pass additional configuration to telescope to change theme, layout, etc. - require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) -end, { desc = '[/] Fuzzily search in current buffer' }) - -vim.keymap.set('n', 'gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) -vim.keymap.set('n', 'tf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) -vim.keymap.set('n', 'th', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) -vim.keymap.set('n', 'tw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) -vim.keymap.set('n', 'tg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) -vim.keymap.set('n', 'td', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) -vim.keymap.set('n', 'tr', require('telescope.builtin').resume, { desc = '[S]earch [R]esume' }) - --- [[ 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', - 'javascript', - 'typescript', - 'vimdoc', - 'vim', - 'latex', - 'haskell', - 'norg', - 'markdown' - }, - - -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) - auto_install = false, - - highlight = { enable = true }, - indent = { enable = true }, - 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', - -- FUCKS UP VIMTEX COMMANDS! - -- ['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', - }, - }, - }, -} - --- Diagnostic keymaps -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next diagnostic message' }) -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' }) -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' }) - --- [[ Configure LSP ]] --- This function gets run when an LSP connects to a particular buffer. -local on_attach = function(_, 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 - - vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc }) - end - - nmap('rn', vim.lsp.buf.rename, '[R]e[n]ame') - nmap('ca', vim.lsp.buf.code_action, '[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', require('telescope.builtin').lsp_implementations, '[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') - - -- 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') - - -- 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' }) +-- [[ Install 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, + } end +vim.opt.runtimepath:prepend(lazypath) --- Enable the following language servers --- Feel free to add/remove any LSPs that you want here. They will automatically be installed. --- --- 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. --- --- If you want to override the default filetypes that your language server will attach to you can --- define the property 'filetypes' to the map in question. -local servers = { - -- clangd = {}, - -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- tsserver = {}, - -- html = { filetypes = { 'html', 'twig', 'hbs'} }, +-- [[ Plugins ]] +require("lazy").setup({ - lua_ls = { - Lua = { - workspace = { checkThirdParty = false }, - telemetry = { enable = false }, + -- Detect tabstop and shiftwidth automatically + "tpope/vim-sleuth", + + -- "gc" to comment visual regions/lines + { "numToStr/Comment.nvim", opts = {} }, + + -- Git related plugins + "tpope/vim-fugitive", + "tpope/vim-rhubarb", + { + "lewis6991/gitsigns.nvim", + opts = { + signs = { + add = { text = "+" }, + change = { text = "~" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + }, }, }, - -- ltex = { - -- ["dictionary"] = { - -- ["en-US"] = { "Surlykke" } - -- } - -- } -} --- Setup neovim lua configuration -require('neodev').setup() + { -- Shows pending keybinds + "folke/which-key.nvim", + event = "VimEnter", + config = function() + require("which-key").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) - --- Ensure the servers above are installed -local mason_lspconfig = require 'mason-lspconfig' - -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], - filetypes = (servers[server_name] or {}).filetypes, - } - end -} - --- [[ Configure nvim-cmp ]] --- See `:help cmp` -local cmp = require 'cmp' -local luasnip = require 'luasnip' -require('luasnip.loaders.from_vscode').lazy_load({ - exclude = { "tex" } -}) -require('luasnip.loaders.from_snipmate').lazy_load({ - exclude = { "tex" } -}) - -luasnip.config.setup { - enable_autosnippets = true, - store_selection_keys = "", -} - -cmp.setup { - snippet = { - expand = function(args) - luasnip.lsp_expand(args.body) + -- Document existing key chains + require("which-key").register { + -- Naming leader-key-groups + ["c"] = { name = "[C]ode", _ = "which_key_ignore" }, + ["d"] = { name = "[D]ocument", _ = "which_key_ignore" }, + ["r"] = { name = "[R]ename", _ = "which_key_ignore" }, + ["s"] = { name = "[S]earch", _ = "which_key_ignore" }, + ["w"] = { name = "[W]orkspace", _ = "which_key_ignore" }, + ["o"] = { name = "[O]rgmode", _ = "which_key_ignore" }, + } 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.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - } - -- 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() - if luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { 'i', 's' }), - }, - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = "neorg" } - }, -} --- The line beneath this is called `modeline`. See `:help modeline` --- vim: ts=2 sts=2 sw=2 et + -- Fuzzy Finder (files, lsp, etc) + { + "nvim-telescope/telescope.nvim", + event = "VimEnter", + branch = "0.1.x", + dependencies = { + { "nvim-lua/plenary.nvim" }, + { -- If encountering errors, see telescope-fzf-native README + "nvim-telescope/telescope-fzf-native.nvim", + build = "make", + cond = function() + return vim.fn.executable "make" == 1 + end, + }, + { "nvim-telescope/telescope-ui-select.nvim" }, + { "nvim-tree/nvim-web-devicons", enabled = vim.g.have_nerd_font }, + }, + config = function() + require("telescope").setup { + defaults = { + mappings = { + i = { [""] = "to_fuzzy_refine" }, + }, + }, + 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") + + -- See `:help telescope.builtin` + local builtin = require "telescope.builtin" + vim.keymap.set("n", "sh", builtin.help_tags, { desc = "[S]earch [H]elp" }) + vim.keymap.set("n", "sk", builtin.keymaps, { desc = "[S]earch [K]eymaps" }) + vim.keymap.set("n", "sf", builtin.find_files, { desc = "[S]earch [F]iles" }) + vim.keymap.set("n", "ss", builtin.builtin, { desc = "[S]earch [S]elect Telescope" }) + vim.keymap.set("n", "sw", builtin.grep_string, { desc = "[S]earch current [W]ord" }) + vim.keymap.set("n", "sg", builtin.live_grep, { desc = "[S]earch by [G]rep" }) + vim.keymap.set("n", "sd", builtin.diagnostics, { desc = "[S]earch [D]iagnostics" }) + vim.keymap.set("n", "sr", builtin.resume, { desc = "[S]earch [R]esume" }) + vim.keymap.set("n", "s.", builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set("n", "sg", builtin.git_files, { desc = "[S]earch [G]it Files" }) + vim.keymap.set("n", "", builtin.buffers, { desc = "[ ] Find existing buffers" }) + -- Overriding default behavior and theme + vim.keymap.set("n", "/", function() + -- You can pass additional configuration to telescope to change theme, layout, etc. + builtin.current_buffer_fuzzy_find(require("telescope.themes").get_dropdown { + winblend = 10, + previewer = false, + }) + end, { desc = "[/] Fuzzily search in current buffer" }) + + -- Also possible to pass additional configuration options. + -- See `:help telescope.builtin.live_grep()` for information about particular keys + vim.keymap.set("n", "s/", function() + 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", "sn", function() + builtin.find_files { cwd = vim.fn.stdpath "config" } + end, { desc = "[S]earch [N]eovim files" }) + end, + }, + + { -- LSP Configuration & Plugins + "neovim/nvim-lspconfig", + dependencies = { + -- Automatically install LSPs to stdpath for neovim + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", + + -- Useful status updates for LSP + { "j-hui/fidget.nvim", opts = {} }, + + -- Lua LSP for Neovim config + { "folke/neodev.nvim", opts = {} }, + }, + + config = function() + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }), + callback = function(event) + -- Lua helper function + local nmap = function(keys, func, desc) + vim.keymap.set("n", keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) + end + + -- Jump to the definition of the word under your cursor. + -- This is where a variable was first declared, or where a function is defined, etc. + -- To jump back, press . + nmap("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition") + + -- Find references for the word under your cursor. + nmap("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") + + -- Jump to the implementation of the word under your cursor. + -- Useful when your language has ways of declaring types without an actual implementation. + nmap("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") + + -- Jump to the type of the word under your cursor. + -- Useful when you're not sure what type a variable is and you want to see + -- the definition of its *type*, not where it was *defined*. + nmap("D", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition") + + -- Fuzzy find all the symbols in your current document. + -- Symbols are things like variables, functions, types, etc. + nmap("ds", require("telescope.builtin").lsp_document_symbols, "[D]ocument [S]ymbols") + + -- Fuzzy find all the symbols in your current workspace + -- Similar to document symbols, except searches over your whole project. + nmap("ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]ymbols") + + -- Rename the variable under your cursor + -- Most Language Servers support renaming across files, etc. + nmap("rn", vim.lsp.buf.rename, "[R]e[n]ame") + + -- Execute a code action, usually your cursor needs to be on top of an error + -- or a suggestion from your LSP for this to activate. + nmap("ca", vim.lsp.buf.code_action, "[C]ode [A]ction") + + -- Opens a popup that displays documentation about the word under your cursor + -- See `:help K` for why this keymap + nmap("K", vim.lsp.buf.hover, "Hover Documentation") + + -- WARN: This is not Goto Definition, this is Goto Declaration. + -- For example, in C this would take you to the header + nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") + + -- Highlight references of word under cursor + local client = vim.lsp.get_client_by_id(event.data.client_id) + if client and client.server_capabilities.documentHighlightProvider then + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { + buffer = event.buf, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { + buffer = event.buf, + callback = vim.lsp.buf.clear_references, + }) + end + end, + }) + + -- Broadcast cmp capabilities to servers. + local capabilities = vim.lsp.protocol.make_client_capabilities() + capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities()) + + -- Available config keys: + -- - cmd (table): Override the default command used to start the server + -- - filetypes (table): Override the default list of associated filetypes for the server + -- - capabilities (table): Override fields in capabilities. Can be used to disable certain LSP features. + -- - settings (table): Override the default settings passed when initializing the server. + local servers = { + lua_ls = { + -- cmd = {...}, + -- filetypes { ...}, + -- capabilities = {}, + settings = { + Lua = { + completion = { + callSnippet = "Replace", + }, + -- diagnostics = { disable = { 'missing-fields' } }, + }, + }, + }, + } + -- Use :Mason to install manually + require("mason").setup() + + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { "stylua" }) + require("mason-tool-installer").setup { ensure_installed = ensure_installed } + + require("mason-lspconfig").setup { + handlers = { + function(server_name) + local server = servers[server_name] or {} + -- This handles overriding only values explicitly passed + -- by the server configuration above. Useful when disabling + -- certain features of an LSP (for example, turning off formatting for tsserver) + server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}) + require("lspconfig")[server_name].setup(server) + end, + }, + } + end, + }, + + { -- Autoformat + "stevearc/conform.nvim", + opts = { + notify_on_error = false, + format_on_save = function(bufnr) + -- Disable "format_on_save lsp_fallback" for languages that don't + -- have a well standardized coding style. You can add additional + -- languages here or re-enable it for the disabled ones. + local disable_filetypes = { c = true, cpp = true } + return { + timeout_ms = 500, + lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype], + } + end, + formatters_by_ft = { + lua = { "stylua" }, + haskell = { "fourmolu" }, + -- Conform can also run multiple formatters sequentially + -- python = { "isort", "black" }, + -- + -- You can use a sub-list to tell conform to run *until* a formatter is found. + -- javascript = { { "prettierd", "prettier" } }, + }, + }, + }, + + { + -- Autocompletion + "hrsh7th/nvim-cmp", + event = "InsertEnter", + dependencies = { + -- Snippet Engine & its associated nvim-cmp source + { + "L3MON4D3/LuaSnip", + -- build needed for regex support + build = (function() + if vim.fn.has "win32" == 1 or vim.fn.executable "make" == 0 then + return + end + return "make install_jsregexp" + end)(), + dependencies = { + -- { + -- -- premade snippets + -- "rafamadriz/friendly-snippets", + -- config = function() + -- require("luasnip.loaders.from_vscode").lazy_load { exclude = { "tex" } } + -- require("luasnip.loaders.from_snipmate").lazy_load { exclude = { "tex" } } + -- end, + -- }, + }, + config = function() + require("luasnip.loaders.from_snipmate").lazy_load() + end, + }, + "saadparwaiz1/cmp_luasnip", + + -- Adds LSP completion capabilities + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + }, + config = function() + local cmp = require "cmp" + local luasnip = require "luasnip" + luasnip.config.setup { enable_autosnippets = true } + + cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + -- old one: completeopt = "menuone,noselect", + completion = { completeopt = "menu,menuone,noinsert" }, + 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.scroll_docs(-8), + [""] = cmp.mapping.scroll_docs(8), + -- Accept ([y]es) the completion + [""] = cmp.mapping.confirm { select = true }, + -- Manually trigger a completion from nvim-cmp (normally not needed) + [""] = cmp.mapping.complete {}, + [""] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { "i", "s" }), + [""] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { "i", "s" }), + }, + sources = { + { name = "nvim_lsp" }, + { name = "luasnip" }, + { name = "path" }, + { name = "neorg" }, + }, + } + end, + }, + + { + "nvim-lualine/lualine.nvim", + dependencies = { + { "nvim-tree/nvim-web-devicons", enabled = vim.g.have_nerd_font }, + }, + opts = { + options = { + icons_enabled = false, + theme = "catppuccin", + component_separators = "|", + section_separators = "", + }, + -- lualine layout: + -- +-------------------------------------------------+ + -- | A | B | C X | Y | Z | + -- +-------------------------------------------------+ + sections = { + lualine_x = {}, + }, + }, + }, + + -- { + -- -- Add indentation guides even on blank lines + -- "lukas-reineke/indent-blankline.nvim", + -- main = "ibl", + -- opts = { + -- -- char = "┊", + -- -- show_trailing_blankline_indent = false, + -- }, + -- }, + + -- Highlight todo, notes, etc in comments + { + "folke/todo-comments.nvim", + event = "VimEnter", + dependencies = { "nvim-lua/plenary.nvim" }, + opts = { signs = false }, + }, + + { -- Collection of various small independent plugins/modules + "echasnovski/mini.nvim", + config = function() + -- Better Around/Inside textobjects + + -- Examples: + -- - yinq - [Y]ank [I]nside [N]ext [']quote + -- - ci' - [C]hange [I]nside [']quote + require("mini.ai").setup { n_lines = 500 } + + -- Add/delete/replace surroundings (brackets, quotes, etc.) + -- + -- - saiw( - [S]urround [A]dd [I]nner [W]ord [)]Paren + -- - sd' - [S]urround [D]elete [']quotes + -- - sr(' - [S]urround [R]eplace [)] ['] + require("mini.surround").setup() + + -- See 'https://github.com/echasnovski/mini.nvim' for more uses + end, + }, + + { + -- Highlight, edit, and navigate code + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + dependencies = { + -- Interact with treesitter textobjects + "nvim-treesitter/nvim-treesitter-textobjects", + -- Keeps function description stuck on top + "nvim-treesitter/nvim-treesitter-context", + }, + opts = { + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { + "bash", + "c", + "haskell", + "lua", + "vim", + "vimdoc", + "org", + "norg", + "markdown", + }, + ignore_install = { "latex" }, + auto_install = true, + indent = { enable = true }, + highlight = { + enable = true, + disable = { "latex" }, + additional_vim_regex_highlighting = { "latex", "markdown" }, + }, + + incremental_selection = { + enable = true, + keymaps = { + -- Defaults + -- init_selection = "gnn", + -- node_incremental = "grn", + -- scope_incremental = "grc", + -- node_decremental = "grm", + + init_selection = "", + node_incremental = "", + scope_incremental = "", + node_decremental = "", + }, + }, + textobjects = { + select = { + enable = true, + -- automatically jump forward to textobj, see targets.vim + lookahead = true, + keymaps = { + -- you can use the capture groups defined in textobjects.scm + ["af"] = { query = "@function.outer", desc = "[a]round [f]unction" }, + ["if"] = { query = "@function.inner", desc = "[i]nner [f]unction" }, + -- [a/i]p is taken for "paragraph". + ["aa"] = { query = "@parameter.outer", desc = "[a]round [a]rgument" }, + ["ia"] = { query = "@parameter.inner", desc = "[i]nner [a]rgument" }, + -- fucks up vimtex commands! + -- ['ac'] = '@class.outer', + -- ['ic'] = '@class.inner', + }, + }, + move = { + enable = true, + set_jumps = true, + 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_interop = { + enable = true, + border = "none", + floating_preview_opts = {}, + peek_definition_code = { + ["df"] = "@function.outer", + ["dF"] = "@class.outer", + }, + }, + }, + }, + + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + end, + }, + + -- Uncomment for debug plugin + -- require 'kickstart.plugins.debug', + + -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins + { import = "custom.plugins" }, +}, { + ui = { + -- Default icons, if no nerd font installed + icons = vim.g.have_nerd_font and {} or { + cmd = "⌘", + config = "🛠", + event = "📅", + ft = "📂", + init = "⚙", + keys = "🗝", + plugin = "🔌", + runtime = "💻", + require = "🌙", + source = "📄", + start = "🚀", + task = "📌", + lazy = "💤 ", + }, + }, +}) + +-- modeline +-- vim: ts=2 sts=4 sw=2 et diff --git a/old-init.md b/old-init.md new file mode 100644 index 00000000..11cf014f --- /dev/null +++ b/old-init.md @@ -0,0 +1,70 @@ +``` +-- Old stuff removed from config, but saving in case it should be added back. +return { -- Adds git related signs to the gutter, as well as utilities for managing changes + "lewis6991/gitsigns.nvim", + opts = { + signs = { + add = { text = "+" }, + change = { text = "~" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + }, + }, + -- Keybinds below have been removed in main init.lua + on_attach = function(bufnr) + vim.keymap.set("n", "hp", require("gitsigns").preview_hunk, { buffer = bufnr, desc = "Preview git hunk" }) + + -- don't override the built-in and fugitive keymaps + local gs = package.loaded.gitsigns + vim.keymap.set({ "n", "v" }, "]c", function() + if vim.wo.diff then + return "]c" + end + vim.schedule(function() + gs.next_hunk() + end) + return "" + end, { expr = true, buffer = bufnr, desc = "Jump to next hunk" }) + vim.keymap.set({ "n", "v" }, "[c", function() + if vim.wo.diff then + return "[c" + end + vim.schedule(function() + gs.prev_hunk() + end) + return "" + end, { expr = true, buffer = bufnr, desc = "Jump to previous hunk" }) + end, + + config = function() + local cmp = require "cmp" + cmp.setup { + mapping = cmp.mapping.preset.insert { + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + } + -- 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() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { "i", "s" }), + }, + } + end, +} +``` diff --git a/snippets/tex.snippets b/snippets/tex.snippets index 5278f7a6..4cdf1c5f 100644 --- a/snippets/tex.snippets +++ b/snippets/tex.snippets @@ -6,6 +6,7 @@ snippet $$ "$Math$" snippet em "\emph{...}" \emph{${1:VISUAL}} + snippet \ "\[ ... \]" \[ ${1}