From 882edc97091d88e74b8069bb6fddbf56b7df25a4 Mon Sep 17 00:00:00 2001 From: Amanda Graven Date: Thu, 30 Nov 2023 15:43:20 +0100 Subject: [PATCH] Overseer, conform, splitkeep, formatting, smoothscroll - Add overseer.nvim - Add conform.nvim - Set splitkeep, remove stabilize.nvim - Set smoothscroll when nightly is available - Set exrc - Make formatting more consistent --- init.lua | 139 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 58 deletions(-) diff --git a/init.lua b/init.lua index 3146a08..81d2705 100644 --- a/init.lua +++ b/init.lua @@ -35,6 +35,7 @@ o.scrolloff = 5 -- Margin between cursor and screen top/bottom o.showmatch = true -- Highlight matching brackets o.splitright = true -- Open new windows below o.splitbelow = true -- Open new windows to the right +o.splitkeep = 'screen' -- Keep window position when creating splits o.title = true -- Set title of terminal window o.updatetime = 300 -- Write swap file every 300 ms (supposedly reduces delays) o.foldlevel = 99 -- Keep all folds open @@ -54,6 +55,10 @@ opt.fillchars = { -- Characters to fill certain types of empty space foldclose='' } opt.diffopt:append({'indent-heuristic', 'algorithm:histogram'}) +if fn.has('nvim-0.10') then + o.smoothscroll = true -- Scroll by screen lines instead of physical lines + opt.display:append('lastline') +end o.tabstop = 4 -- A physical tab is 4 characters wide o.shiftwidth = 4 -- A unit of indentention is 4 levels wide @@ -62,8 +67,11 @@ o.textwidth = 0 -- Comments lines should wrap at 100 chars o.laststatus = 3 -- Use one global status bar -- Set key g.mapleader = ' ' +g.maplocalleader = '\\' vim.cmd 'filetype plugin indent on' +o.exrc = true -- Load .nvim.lua .nvimrc and .exrc files + -- Enable persistent undo if fn.has('persistent_undo') then o.undodir = fn.stdpath('data') .. '/undo' @@ -137,7 +145,7 @@ do ['ZD'] = {'bdelete', 'Delete buffer'}, } - which_key.register { [''] = {function () + which_key.register { [''] = {function() local ok, notify = pcall(require, 'notify') if ok then notify.dismiss{} @@ -251,7 +259,7 @@ require'packer'.startup(function(use) style = 'night' } end} - use {'catppuccin/nvim', as = 'catppuccin', config = function () + use {'catppuccin/nvim', as = 'catppuccin', config = function() vim.g.catppuccin_flavour = 'latte' require'catppuccin'.setup { integrations = { @@ -282,6 +290,16 @@ require'packer'.startup(function(use) -- Editing -- use 'LunarWatcher/auto-pairs' use 'ojroques/nvim-bufdel' + use {'stevearc/conform.nvim', config = function() + require'conform'.setup {} + vim.api.nvim_create_user_command( + 'Conform', + function() + require'conform'.format() + end, + {} + ) + end} --use 'yuttie/comfortable-motion.vim' use {'jbyuki/instant.nvim', config = function () vim.g.instant_username = 'agraven' @@ -350,7 +368,7 @@ require'packer'.startup(function(use) -- UI elements -- use 'vim-airline/vim-airline' use 'vim-airline/vim-airline-themes' - use 'romgrk/barbar.nvim' + use {'taketwo/barbar.nvim', branch = 'schedule-wrap'} use {'luckasRanarison/clear-action.nvim', config = function() require'clear-action'.setup { signs = { enable = false }, @@ -418,7 +436,7 @@ require'packer'.startup(function(use) pathMkfifo = 'mkfifo', pathPkill = 'pkill', env = {}, - args = function () + args = function() return vim.fn.split(vim.fn.input('Arguments: ', '', 'file')) end, }, @@ -491,13 +509,13 @@ require'packer'.startup(function(use) use {'rcarriga/nvim-dap-ui', config = function() local dapui, dap = require'dapui', require'dap' dapui.setup() - dap.listeners.after.event_initialized.dapui_config = function () + dap.listeners.after.event_initialized.dapui_config = function() dapui.open {} end - dap.listeners.before.event_terminated.dapui_config = function () + dap.listeners.before.event_terminated.dapui_config = function() dapui.close {} end - dap.listeners.before.event_exited.dapui_config = function () + dap.listeners.before.event_exited.dapui_config = function() dapui.close {} end require'which-key'.register { @@ -530,7 +548,7 @@ require'packer'.startup(function(use) }, } end} - use {'j-hui/fidget.nvim', branch = 'legacy'} + use {'j-hui/fidget.nvim', config = function() require'fidget'.setup() end} use 'tpope/vim-fugitive' use 'tpope/vim-rhubarb' use 'shumphrey/fugitive-gitlab.vim' @@ -557,7 +575,7 @@ require'packer'.startup(function(use) -- figure out how to ensure java-test and java-debug-adapter } end} - use {'NeogitOrg/neogit', config = function () + use {'NeogitOrg/neogit', config = function() require'neogit'.setup { disable_context_highlighting = true, integrations = { @@ -576,8 +594,11 @@ require'packer'.startup(function(use) vim.notify = require'notify' require'telescope'.load_extension('notify') end} - use {'luukvbaal/stabilize.nvim', config = function() - require'stabilize'.setup() + use {'stevearc/overseer.nvim', after = 'nvim-dap', config = function() + require'overseer'.setup() + vim.keymap.set('n', 'rr', 'OverseerToggle right', { desc = "Open" }) + vim.keymap.set('n', 'rn', 'OverseerRun', { desc = "New task" }) + vim.keymap.set('n', 'rc', 'OverseerRunCmd', { desc = "Run shell command" }) end} use 'mhinz/vim-startify' use {'nvim-telescope/telescope.nvim', after = 'which-key.nvim', config = function() @@ -624,15 +645,19 @@ require'packer'.startup(function(use) [""] = {'Telescope', 'List pickers'}, f = {'Telescope find_files', 'Files'}, F = {'Telescope file_browser', 'File browser'}, - [''] = {function () - vim.ui.input({ completion = 'dir' }, function (input) - telescope.builtin.find_files { search_dirs = {input} } - end) - end, 'Files in subdirectory'}, + [''] = { + function() + vim.ui.input( + { completion = 'dir' }, + function(input) telescope.builtin.find_files { search_dirs = {input} } + end) + end, + 'Files in subdirectory' + }, d = {'Telescope find_files find_command=fd,--type,d,-I', 'Directories'}, r = {'Telescope oldfiles', 'Recent files'}, g = {'Telescope live_grep', 'Grep'}, - G = {function () + G = {function() vim.ui.input({ completion = 'dir' }, function(input) telescope.builtin.live_grep { search_dirs = {input} } end) @@ -654,13 +679,13 @@ require'packer'.startup(function(use) use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make', after = 'telescope.nvim', config = function() require'telescope'.load_extension('fzf') end} - use {'nvim-telescope/telescope-file-browser.nvim', after = 'telescope.nvim', config = function () + use {'nvim-telescope/telescope-file-browser.nvim', after = 'telescope.nvim', config = function() require'telescope'.load_extension('file_browser') end} - use {'nvim-telescope/telescope-project.nvim', after = 'telescope.nvim', config = function () + use {'nvim-telescope/telescope-project.nvim', after = 'telescope.nvim', config = function() require'telescope'.load_extension('project') end} - use {'nvim-telescope/telescope-ui-select.nvim', after = 'telescope.nvim', config = function () + use {'nvim-telescope/telescope-ui-select.nvim', after = 'telescope.nvim', config = function() require'telescope'.load_extension('ui-select') end} use {'nvim-telescope/telescope-dap.nvim', after = 'telescope.nvim', config = function() @@ -689,7 +714,7 @@ require'packer'.startup(function(use) use 'antoinemadec/FixCursorHold.nvim' end use 'lewis6991/impatient.nvim' -- speeds up load times - use {'ellisonleao/dotenv.nvim', config = function () + use {'ellisonleao/dotenv.nvim', config = function() require'dotenv'.setup { enable_on_load = false, verbose = true, @@ -771,7 +796,7 @@ vim.keymap.set('n', 'G', 'tab Git', {desc = 'Git status (new ta ---- gitsigns ---- require'gitsigns'.setup { - on_attach = function () + on_attach = function() local gitsigns = require'gitsigns' vim.keymap.set('n', ']c', gitsigns.next_hunk, {desc = 'Next hunk'}) vim.keymap.set('n', '[c', gitsigns.prev_hunk, {desc = 'Previous hunk'}) @@ -782,7 +807,7 @@ require'gitsigns'.setup { vim.ui.input({ prompt = 'Revision to compare to', completion = "customlist,v:lua.require'gitsigns.cli'.complete", - }, function (revision) + }, function(revision) if not revision then return end gitsigns.change_base(revision, true) end) @@ -835,7 +860,7 @@ end local cmp = require'cmp' local cmp_dap = require'cmp_dap' cmp.setup { - enabled = function () + enabled = function() return vim.bo.buftype ~= 'prompt' or cmp_dap.is_dap_buffer() end, preselect = cmp.PreselectMode.None, @@ -929,9 +954,10 @@ capabilities.textDocument.foldingRange = { ---- lsp: language servers ---- au('LspAttach', { - callback = function (event) + callback = function(event) local bufnr = event.buf local client = vim.lsp.get_client_by_id(event.data.client_id) + if not client then return end local function code_action() local ok, clear_action = pcall(require, 'clear-action') if ok then @@ -947,7 +973,7 @@ au('LspAttach', { i = {'Telescope lsp_implementations', 'Implementation'}, a = {code_action, 'Code action'}, r = {vim.lsp.buf.rename, 'Rename'}, - h = {function() vim.lsp.inlay_hint(0, nil) end, 'Inlay hints'}, + h = {function() vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled()) end, 'Inlay hints'}, l = {vim.lsp.codelens.refresh, 'Show codelenses'}, L = {vim.lsp.codelens.run, 'Run codelens'}, t = {'Telescope lsp_type_definitions', 'Type definition'}, @@ -983,8 +1009,13 @@ au('LspAttach', { }, {buffer = bufnr, mode = 'i'}) vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc' + if pcall(require, 'conform') == true then + vim.bo.formatexpr = "v:lua.require'conform'.formatexpr()" + end - require'nvim-navic'.attach(client, bufnr) + if client.server_capabilities.documentSymbolProvider then + require'nvim-navic'.attach(client, bufnr) + end end }) @@ -1017,8 +1048,8 @@ require'lspconfig'.lua_ls.setup { require'lspconfig'.bashls.setup(default) require'lspconfig'.clangd.setup(default) au('FileType', { - pattern = 'java', - callback = function () + pattern = 'java', + callback = function() local ok, jdtls = pcall(require, 'jdtls') if not ok then return end jdtls.tests = require'jdtls.tests' @@ -1048,7 +1079,7 @@ au('FileType', { init_options = { -- JDTLS plugins - bundles = (function () + bundles = (function() -- add java-debug-adapter local bundles = { vim.fn.glob(mason_path'java-debug-adapter' .. '/extension/server/com.microsoft.java.debug.plugin-*.jar', true) @@ -1065,7 +1096,7 @@ au('FileType', { capabilities = capabilities, - on_attach = function (client, bufnr) + on_attach = function(client, bufnr) jdtls.setup_dap() end, } @@ -1078,10 +1109,10 @@ require'lspconfig'.pyright.setup(default) -- Defer setup to silence deprecation notice au('FileType', { pattern = 'sql', - callback = function () + callback = function() require'lspconfig'.sqls.setup { capabilities = capabilities, - on_attach = function (client, bufnr) + on_attach = function(client, bufnr) local ok, sqls = pcall(require, 'sqls') if not ok then return end sqls.on_attach(client, bufnr) @@ -1140,24 +1171,16 @@ require'rust-tools'.setup { loadOutDirsFromCheck = true, }, checkOnSave = true, - -- Use cargo lints for error checking if available, otherwise fall back to regular clippy - check = (function() - if vim.fn.executable('cargo-lints') then - return { - overrideCommand = {"cargo", "lints", "clippy", "--workspace", "--message-format=json", "--all-targets"} - } - else - return { - -- Use clippy for error checking - command = "clippy", - -- Also run checks for tests - allTargets = true, - } - end - end)(), + -- Error checking settings + check = { + -- Use clippy for error checking + command = "clippy", + -- Also run checks for tests + allTargets = true, + }, diagnostics = { -- Disable diagnostics with false positives - disabled = {'unresolved-import'}; + disabled = {'unresolved-import'}, }, procMacro = { -- Enable proc macro support @@ -1178,7 +1201,7 @@ g.startify_change_to_vcs_root = 1 -- Change working dir to version control roo g.startify_fortune_use_unicode = 1 -- Enable unicode box drawing in fortune message -- Items to show on the startup screen g.startify_lists = { - { type = 'dir', header = {' Recently used '.. fn.getcwd()} }, + { type = 'dir', header = {' Recently used ' .. fn.getcwd()} }, { type = 'files', header = {' Recently used'} }, { type = 'sessions', header = {' Sessions'} }, { type = 'bookmarks', header = {' Bookmarks'} }, @@ -1260,15 +1283,15 @@ require('nvim-tree').setup { } -- Handle restoring sessions with nvim-tree windows properly au('BufEnter', { - pattern = 'NvimTree*', - callback = function() - local api = require('nvim-tree.api') - local view = require('nvim-tree.view') + pattern = 'NvimTree*', + callback = function() + local api = require('nvim-tree.api') + local view = require('nvim-tree.view') - if not view.is_visible() then - api.tree.open() - end - end, + if not view.is_visible() then + api.tree.open() + end + end, }) vim.cmd'highlight NvimTreeOpenedFile guifg=NONE guibg=NONE gui=italic'