From 6d8480b8b5f5054a34ab15e45fae99b216162814 Mon Sep 17 00:00:00 2001 From: iofq Date: Thu, 22 Aug 2024 03:30:25 -0500 Subject: [PATCH] tweaks and ftplugins --- nix/mkNeovim.nix | 7 +++- nix/neovim-overlay.nix | 20 ++-------- nvim/ftplugin/go.lua | 1 + nvim/ftplugin/php.lua | 1 + nvim/lua/config/init.lua | 2 +- nvim/lua/plugins/completion.lua | 3 +- nvim/lua/plugins/lsp.lua | 10 ++--- nvim/lua/plugins/mini.lua | 38 ++++++------------ nvim/lua/plugins/misc.lua | 68 +++++++++++++++------------------ nvim/lua/plugins/telescope.lua | 64 ++++++++++++++++++++++++++++--- nvim/lua/plugins/treesitter.lua | 9 +++++ 11 files changed, 128 insertions(+), 95 deletions(-) create mode 100644 nvim/ftplugin/go.lua create mode 100644 nvim/ftplugin/php.lua diff --git a/nix/mkNeovim.nix b/nix/mkNeovim.nix index e71663a..a5e5036 100644 --- a/nix/mkNeovim.nix +++ b/nix/mkNeovim.nix @@ -92,11 +92,14 @@ with lib; buildPhase = '' mkdir -p $out/lua + mkdir -p $out/ftplugin ''; installPhase = '' - cp -r lua $out/lua + cp -r lua $out/ rm -r lua + cp -r ftplugin $out/ + rm -r ftplugin ''; }; @@ -104,7 +107,7 @@ with lib; # It wraps the user init.lua, prepends the lua lib directory to the RTP # and prepends the nvim and after directory to the RTP initLua = '' - vim.opt.rtp:prepend('${nvimRtp}/lua') + vim.opt.rtp:prepend('${nvimRtp}') LAZY_OPTS = { performance = { reset_packpath = false, diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index b411998..7e579cb 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -35,15 +35,14 @@ with final.pkgs.lib; let neogit none-ls-nvim nightfox-nvim + nvim-autopairs nvim-cmp nvim-dap nvim-dap-go nvim-dap-ui nvim-early-retirement nvim-lspconfig - nvim-neoclip-lua nvim-nio - nvim-autopairs nvim-treesitter-context nvim-treesitter-textobjects (nvim-treesitter.withPlugins(p: with p; [ @@ -81,11 +80,13 @@ with final.pkgs.lib; let toggleterm-nvim trouble-nvim undotree + yanky-nvim workspace-diagnostics-nvim ]; basePackages = with pkgs; [ ripgrep + fd ]; extraPackages = with pkgs; [ # linters @@ -121,19 +122,4 @@ in { nvim-luarc-json = final.mk-luarc-json { plugins = all-plugins; }; - - # You can add as many derivations as you like. - # Use `ignoreConfigRegexes` to filter out config - # files you would not like to include. - # - # For example: - # - # nvim-pkg-no-telescope = mkNeovim { - # plugins = []; - # ignoreConfigRegexes = [ - # "^plugin/telescope.lua" - # "^ftplugin/.*.lua" - # ]; - # inherit extraPackages; - # }; } diff --git a/nvim/ftplugin/go.lua b/nvim/ftplugin/go.lua new file mode 100644 index 0000000..3436b9c --- /dev/null +++ b/nvim/ftplugin/go.lua @@ -0,0 +1 @@ +vim.opt_local.expandtab = false diff --git a/nvim/ftplugin/php.lua b/nvim/ftplugin/php.lua new file mode 100644 index 0000000..3f3eef4 --- /dev/null +++ b/nvim/ftplugin/php.lua @@ -0,0 +1 @@ +vim.opt.tabstop = 4 diff --git a/nvim/lua/config/init.lua b/nvim/lua/config/init.lua index 87bd5a4..4e1ded1 100644 --- a/nvim/lua/config/init.lua +++ b/nvim/lua/config/init.lua @@ -33,7 +33,7 @@ vim.api.nvim_create_autocmd('VimEnter', { command = 'silent !mkdir -p ' .. undopath, group = vim.api.nvim_create_augroup('Init', {}), }) --- open :g in buffers +-- open :h in buffers vim.api.nvim_create_autocmd('BufWinEnter', { pattern = '*', callback = function(event) diff --git a/nvim/lua/plugins/completion.lua b/nvim/lua/plugins/completion.lua index beaf4e6..938be4b 100644 --- a/nvim/lua/plugins/completion.lua +++ b/nvim/lua/plugins/completion.lua @@ -34,6 +34,7 @@ return { { name = 'luasnip' }, { name = 'buffer' }, { name = 'path' }, + { name = 'treesitter', keyword_length = 3 }, }), } @@ -48,7 +49,7 @@ return { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = 'path' }, - }, { + { name = 'buffer' }, { name = 'cmdline' }, }), matching = { disallow_symbol_nonprefix_matching = false }, diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua index a4293e1..660e486 100644 --- a/nvim/lua/plugins/lsp.lua +++ b/nvim/lua/plugins/lsp.lua @@ -28,7 +28,7 @@ return { }, { 'neovim/nvim-lspconfig', - lazy = false, + event = 'VeryLazy', dependencies = { 'hrsh7th/cmp-nvim-lsp', }, @@ -39,7 +39,6 @@ return { lspconfig.util.default_config.capabilities, require('cmp_nvim_lsp').default_capabilities() ) - vim.lsp.inlay_hint.enable(true) lspconfig.gopls.setup { settings = { gopls = { @@ -54,17 +53,17 @@ return { }, hints = { assignVariableTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, constantValues = true, functionTypeParameters = true, rangeVariableTypes = true, + parameterNames = true, }, usePlaceholders = true, staticcheck = true, }, }, - on_attach = function() - vim.api.nvim_command('au BufWritePre lua vim.lsp.buf.format { async = false }') - end, } lspconfig.jedi_language_server.setup {} lspconfig.nil_ls.setup {} @@ -97,6 +96,7 @@ return { callback = function(ev) local bufnr = ev.buf local client = vim.lsp.get_client_by_id(ev.data.client_id) + vim.api.nvim_command('au BufWritePre lua vim.lsp.buf.format { async = false }') vim.keymap.set( 'n', 'K', diff --git a/nvim/lua/plugins/mini.lua b/nvim/lua/plugins/mini.lua index 4472aa0..7b035be 100644 --- a/nvim/lua/plugins/mini.lua +++ b/nvim/lua/plugins/mini.lua @@ -3,6 +3,7 @@ return { 'echasnovski/mini.nvim', lazy = false, config = function() + require('mini.basics').setup { mappings = { windows = true, }, } require('mini.tabline').setup({ tabpage_section = 'right', show_icons = false, @@ -12,21 +13,12 @@ return { active = function() local mode, mode_hl = MiniStatusline.section_mode {} local git = function() - local summary = vim.b.gitsigns_head - if summary == nil then - return '' - end - summary = '~' .. summary - - return summary == '' and '' or summary + local g = vim.b.gitsigns_head + return (g == nil) and '' or g end local diff = function() - local summary = vim.b.gitsigns_status - if summary == nil then - return '' - end - - return summary + local g = vim.b.gitsigns_status + return (g == nil) and '' or g end local diagnostics = MiniStatusline.section_diagnostics { trunc_width = 75 } local lsp = MiniStatusline.section_lsp { trunc_width = 75 } @@ -34,17 +26,16 @@ return { local search = MiniStatusline.section_searchcount { trunc_width = 75 } return MiniStatusline.combine_groups { - { hl = mode_hl, strings = { mode } }, + { hl = mode_hl, strings = { mode } }, '%<', -- Mark general truncate point { hl = 'MiniStatuslineFilename', strings = { filename } }, '%=', -- End left alignment - { hl = 'MiniStatusDevinfo', strings = { git(), diff(), diagnostics, lsp} }, - { hl = mode_hl, strings = { search } }, + { hl = 'MiniStatusDevinfo', strings = { git(), diff(), diagnostics, lsp } }, + { hl = mode_hl, strings = { search } }, } end, inactive = function() local filename = MiniStatusline.section_filename { trunc_width = 140 } - return MiniStatusline.combine_groups { { hl = 'MiniStatuslineFilename', strings = { filename } }, } @@ -60,16 +51,13 @@ return { require('mini.surround').setup() require('mini.jump2d').setup { mappings = { start_jumping = 'S' } } require('mini.splitjoin').setup { detect = { separator = '[,;\n]' }, } - require('mini.basics').setup { mappings = { windows = true, }, } require('mini.trailspace').setup() - vim.api.nvim_create_user_command('Trim', function() - require('mini.trailspace').trim() - end, {}) + vim.api.nvim_create_user_command('Trim', require('mini.trailspace').trim, {}) local indent = require('mini.indentscope') indent.setup { + symbol = '│', draw = { delay = 0 }, } - indent.gen_animation.none() local miniclue = require('mini.clue') miniclue.setup { @@ -92,7 +80,6 @@ return { }, } - local map = require('mini.map') map.setup { symbols = { @@ -124,7 +111,7 @@ return { files.setup { mappings = { synchronize = "w", - go_in_plus="" + go_in_plus = "" }, windows = { preview = true, @@ -135,7 +122,6 @@ return { vim.api.nvim_create_autocmd("User", { pattern = "MiniFilesBufferCreate", callback = function(args) - local buf_id = args.data.buf_id vim.keymap.set( "n", "c", @@ -143,7 +129,7 @@ return { files.synchronize() files.close() end, - { buffer = buf_id } + { buffer = args.data.buf_id } ) end, }) diff --git a/nvim/lua/plugins/misc.lua b/nvim/lua/plugins/misc.lua index de9d412..8cc8b72 100644 --- a/nvim/lua/plugins/misc.lua +++ b/nvim/lua/plugins/misc.lua @@ -38,26 +38,7 @@ return { { 'chrisgrieser/nvim-early-retirement', event = 'VeryLazy', - opts = { minimumBufferNum = 6 }, - }, - { - 'AckslD/nvim-neoclip.lua', - event = 'VeryLazy', - dependencies = { - 'nvim-telescope/telescope.nvim', - }, - opts = { - default_register = '+', - }, - config = function(_, opts) - require('neoclip').setup(opts) - vim.keymap.set( - 'n', - 'fp', - 'Telescope neoclip', - { noremap = true, silent = true, desc = 'Pick clipboard history' } - ) - end, + opts = { minimumBufferNum = 10 }, }, { 'leath-dub/snipe.nvim', @@ -84,10 +65,21 @@ return { default_args = { DiffviewOpen = { '--imply-local' }, }, + keymaps = { + view = { + { { "n" }, "q", vim.cmd.DiffviewClose, { desc = "Close Diffview" } }, + }, + file_panel = { + { { "n" }, "q", vim.cmd.DiffviewClose, { desc = "Close Diffview" } }, + }, + file_history_panel = { + { { "n" }, "q", vim.cmd.DiffviewClose, { desc = "Close Diffview" } }, + } + } + }, + keys = { + { 'nb', vim.cmd.DiffviewOpen, noremap = true, desc = 'diffview open' } }, - config = function() - vim.keymap.set('n', 'nb', vim.cmd.DiffviewOpen, { noremap = true, desc = 'diffview open' }) - end, }, { 'NeogitOrg/neogit', @@ -123,7 +115,7 @@ return { { 'EdenEast/nightfox.nvim', lazy = false, - priority = 10000, + priority = 1000, opts = { options = { transparent = true, @@ -133,18 +125,18 @@ return { config = function(_, opts) require('nightfox').setup(opts) vim.cmd('colorscheme terafox') - vim.schedule(function() - vim.api.nvim_set_hl(0, 'MiniNotifyNormal', { bg = 'none' }) - vim.api.nvim_set_hl(0, 'MiniNotifyTitle', { bg = 'none' }) - vim.api.nvim_set_hl(0, 'MiniNotifyBorder', { bg = 'none' }) - vim.api.nvim_set_hl(0, 'MiniMapNormal', { bg = 'none' }) - vim.api.nvim_set_hl(0, 'MiniClueNormal', { bg = 'none' }) - vim.api.nvim_set_hl(0, 'StatusLine', { bg = 'none' }) - vim.api.nvim_set_hl(0, 'StatusLineNC', { bg = 'none' }) - vim.api.nvim_set_hl(0, 'GitSignsAdd', { fg = 'green', bold = true }) - vim.api.nvim_set_hl(0, 'GitSignsDelete', { fg = 'red', bold = true }) - vim.api.nvim_set_hl(0, 'GitSignsChange', { fg = 'green', bold = true }) - end) + vim.api.nvim_set_hl(0, 'MiniNotifyNormal', { bg = 'none' }) + vim.api.nvim_set_hl(0, 'MiniNotifyTitle', { bg = 'none' }) + vim.api.nvim_set_hl(0, 'MiniNotifyBorder', { bg = 'none' }) + vim.api.nvim_set_hl(0, 'MiniMapNormal', { bg = 'none' }) + vim.api.nvim_set_hl(0, 'MiniClueNormal', { bg = 'none' }) + vim.api.nvim_set_hl(0, 'MiniTablineFill', { bg = 'none' }) + vim.api.nvim_set_hl(0, 'StatusLine', { bg = 'none' }) + vim.api.nvim_set_hl(0, 'StatusLineNC', { bg = 'none' }) + vim.api.nvim_set_hl(0, 'GitSignsAdd', { fg = 'green', bold = true }) + vim.api.nvim_set_hl(0, 'GitSignsDelete', { fg = 'red', bold = true }) + vim.api.nvim_set_hl(0, 'GitSignsChange', { fg = 'green', bold = true }) + vim.api.nvim_set_hl(0, 'GitSignsCurrentLineBlame', { link = 'Comment' }) end, }, { @@ -157,9 +149,11 @@ return { local gs = package.loaded.gitsigns vim.keymap.set('n', 'gg', gs.preview_hunk, { desc = 'git preview hunk' }) vim.keymap.set('n', 'gr', gs.reset_hunk, { desc = 'git reset hunk' }) + vim.keymap.set('n', 'gd', gs.diffthis, { desc = 'git diff hunk' }) vim.keymap.set('n', 'gb', function() gs.blame_line { full = true } - end, { desc = 'git blame_line' }) + end, { desc = 'git blame_line current' }) + vim.keymap.set('n', 'gB', gs.toggle_current_line_blame, { desc = 'git blame_line toggle' }) vim.keymap.set('v', 'gr', function() gs.reset_hunk { vim.fn.line('.'), vim.fn.line('v') } end, { desc = 'git reset hunk' }) diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua index 7fe925e..3b9c4df 100644 --- a/nvim/lua/plugins/telescope.lua +++ b/nvim/lua/plugins/telescope.lua @@ -12,6 +12,27 @@ return { 'nvim-telescope/telescope-fzf-native.nvim', 'nvim-treesitter/nvim-treesitter', 'tiagovla/scope.nvim', + { + 'gbprod/yanky.nvim', + config = function() + local mapping = require("yanky.telescope.mapping") + require("yanky").setup({ + picker = { + telescope = { + mappings = { + default = mapping.set_register( + require("yanky.utils").get_default_register() + ), + }, + }, + }, + ring = { + storage = "memory", + }, + }) + vim.keymap.set({"n","x"}, "y", "(YankyYank)") + end, + }, }, config = function() local telescope = require('telescope') @@ -48,6 +69,7 @@ return { } telescope.load_extension('fzf') telescope.load_extension('scope') + telescope.load_extension('yank_history') local b = require('telescope.builtin') -- Fall back to find_files if not in a git repo @@ -59,24 +81,48 @@ return { end end - vim.keymap.set('n', 'ff', project_files, { noremap = true, silent = true, desc = 'Fuzzy find git files' }) - vim.keymap.set('n', 'fg', b.find_files, { noremap = true, silent = true, desc = 'Fuzzy find files' }) + vim.keymap.set( + 'n', + 'ff', + project_files, + { noremap = true, silent = true, desc = 'Fuzzy find git files' } + ) + vim.keymap.set( + 'n', + 'fg', + b.find_files, + { noremap = true, silent = true, desc = 'Fuzzy find files' } + ) vim.keymap.set( 'n', 'fc', b.command_history, { noremap = true, silent = true, desc = 'Fuzzy find command_history' } ) - vim.keymap.set('n', 'fa', b.live_grep, { noremap = true, silent = true, desc = 'Fuzzy find grep' }) + vim.keymap.set( + 'n', + 'fa', + b.live_grep, + { noremap = true, silent = true, desc = 'Fuzzy find grep' } + ) vim.keymap.set( 'n', 'f8', b.grep_string, { noremap = true, silent = true, desc = 'Fuzzy find grep current word' } ) - vim.keymap.set('n', 'fq', b.quickfix, { noremap = true, silent = true, desc = 'Fuzzy find quickfix' }) - vim.keymap.set('n', 'f?', b.builtin, { noremap = true, silent = true, desc = 'See all pickers' }) - vim.keymap.set('n', 'f.', b.resume, { noremap = true, silent = true, desc = 'Fuzzy find resume' }) + vim.keymap.set( + 'n', + 'f?', + b.builtin, + { noremap = true, silent = true, desc = 'See all pickers' } + ) + vim.keymap.set( + 'n', + 'f.', + b.resume, + { noremap = true, silent = true, desc = 'Fuzzy find resume' } + ) vim.keymap.set( 'n', 'fs', @@ -89,6 +135,12 @@ return { 'Telescope scope buffers', { noremap = true, silent = true, desc = 'Pick buffers (scope.nvim)' } ) + vim.keymap.set( + 'n', + 'fp', + 'Telescope yank_history', + { noremap = true, silent = true, desc = 'Pick history (yanky.nvim)' } + ) end, }, } diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index 44c53e5..36bc496 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -26,6 +26,9 @@ return { autopairs = { enable = true, }, + matchup = { + enable = true, + }, textobjects = { select = { enable = true, @@ -35,6 +38,10 @@ return { ['if'] = '@function.inner', ['aa'] = '@statement.outer', ['ia'] = '@parameter.inner', + ["ik"] = "@assignment.lhs", + ["ak"] = "@assignment.inner", + ["iv"] = "@assignment.rhs", + ["av"] = "@assignment.outer", }, }, move = { @@ -42,10 +49,12 @@ return { goto_next_start = { [']a'] = '@parameter.inner', [']f'] = '@function.outer', + [']]'] = '@block.inner', }, goto_previous_start = { ['[a'] = '@parameter.inner', ['[f'] = '@function.outer', + ['[['] = '@block.inner', }, }, swap = {