diff --git a/init.lua b/init.lua index 82dc745..89793b5 100644 --- a/init.lua +++ b/init.lua @@ -1,7 +1,8 @@ -- Modules +vim.loader.enable() vim.opt.runtimepath:remove("/usr/share/nvim/site") -for _, m in ipairs({ "netrw", "netrwPlugin", "gzip", "tarPlugin", "zipPlugin", "tutor_mode_plugin" }) do - vim.g["loaded_" .. m] = 1 -- Block unused built-in modules +for _, m in ipairs({ "netrw", "netrwPlugin", "gzip", "tarPlugin", "zipPlugin", "tutor_mode_plugin", "rplugin" }) do + vim.g["loaded_" .. m] = 1 end -- Config Global @@ -12,9 +13,10 @@ local gr = vim.api.nvim_create_augroup("custom-config", {}) _G.Config = { now = function(f) misc.safely("now", f) end, later = function(f) misc.safely("later", f) end, - autocmd = function(event, pattern, callback, desc) - vim.api.nvim_create_autocmd(event, { group = gr, pattern = pattern, callback = callback, desc = desc }) + autocmd = function(event, pattern, callback, desc, once) + vim.api.nvim_create_autocmd(event, { group = gr, pattern = pattern, callback = callback, desc = desc, once = once }) end } Config.now_if_args = vim.fn.argc(-1) > 0 and Config.now or Config.later + diff --git a/nvim-pack-lock.json b/nvim-pack-lock.json index a456809..6b013a2 100644 --- a/nvim-pack-lock.json +++ b/nvim-pack-lock.json @@ -17,7 +17,7 @@ "src": "https://github.com/neovim/nvim-lspconfig" }, "nvim-treesitter": { - "rev": "427e9222363d07c32d6db6169e4049c28d58d141", + "rev": "41416e81a6c7f4af4984395bfe0cd8d174e70976", "src": "https://github.com/nvim-treesitter/nvim-treesitter" }, "rose-pine": { diff --git a/plugin/10_options.lua b/plugin/10_options.lua index 7e684e7..15b7f2a 100644 --- a/plugin/10_options.lua +++ b/plugin/10_options.lua @@ -21,7 +21,7 @@ vim.o.wrap = false -- Don't visually wrap lines vim.o.winborder = 'rounded' -- Use border in floating windows vim.o.pumborder = 'rounded' -- Use border in popup menu vim.o.cmdheight = 0 -- Hide the command line when not in use -vim.cmd('syntax off') -- Disable legacy syntax highlighting +vim.g.syntax_on = 0 -- Disable legacy syntax highlighting require("vim._core.ui2").enable({ -- Enable new ui (requires nightly) msg = { targets = "msg" } }) @@ -36,7 +36,6 @@ vim.o.smartcase = true -- Respect case if search pattern has upper case vim.o.spelloptions = 'camel' -- Treat camelCase word parts as separate words vim.o.tabstop = 2 -- Show tab as this number of spaces vim.o.virtualedit = 'block' -- Allow going past end of line in blockwise mode -vim.opt.autoread = true -- Do not prompt to reread files on update vim.o.complete = '.,w,b,kspell' -- Use less sources vim.o.completeopt = 'menuone,noselect,fuzzy,nosort' -- Use custom behavior diff --git a/plugin/20_keymaps.lua b/plugin/20_keymaps.lua index 4e9d298..f960d0b 100644 --- a/plugin/20_keymaps.lua +++ b/plugin/20_keymaps.lua @@ -14,96 +14,117 @@ Config.leader_group_clues = { } -- Keymap Helpers -local function map(mode, lhs, rhs, desc) - vim.keymap.set(mode, lhs, rhs, { desc = desc, silent = true }) +local nmap_leader = function(suffix, rhs, desc) + vim.keymap.set("n", "" .. suffix, rhs, { desc = desc, silent = true }) end -local function leader(suffix, rhs, desc, mode) - map(mode or "n", "" .. suffix, rhs, desc) +local xmap_leader = function(suffix, rhs, desc) + vim.keymap.set("x", "" .. suffix, rhs, { desc = desc, silent = true }) end -- Buffers -leader("bd", "bdelete", "Delete") -leader("bD", "bdelete!", "Delete!") -leader("bw", "bwipeout", "Wipeout") -leader("bW", "bwipeout!", "Wipeout!") -leader("bo", function() +local new_scratch_buffer = function() + vim.api.nvim_win_set_buf(0, vim.api.nvim_create_buf(true, true)) +end + +local close_invisible_buffers = function() local visible = vim.iter(vim.api.nvim_list_wins()):map(vim.api.nvim_win_get_buf):totable() vim.iter(vim.api.nvim_list_bufs()) :filter(function(buf) return not vim.list_contains(visible, buf) end) :each(function(buf) pcall(vim.api.nvim_buf_delete, buf, { force = false }) end) -end, "Close invisible buffers") +end + +nmap_leader("bd", "bdelete", "Delete") +nmap_leader("bD", "bdelete!", "Delete!") +nmap_leader("bs", new_scratch_buffer, "Scratch") +nmap_leader("bw", "bwipeout", "Wipeout") +nmap_leader("bW", "bwipeout!", "Wipeout!") +nmap_leader("bo", close_invisible_buffers, "Close invisible buffers") -- Debug -leader("db", function() require("dap").toggle_breakpoint() end, "Toggle Breakpoint") -leader("dl", function() require("dap").set_breakpoint(nil, nil, vim.fn.input("Log point: ")) end, "Log point") -leader("dc", function() require("dap").continue() end, "Run/Continue") -leader("dC", function() require("dap").run_to_cursor() end, "Run to Cursor") -leader("de", function() require("dap.ui.widgets").hover() end, "Inspect") -leader("dr", function() require("dap").repl.open() end, "Open REPL") -leader("dt", function() require("dap").terminate() end, "Terminate") +nmap_leader("db", "lua require('dap').toggle_breakpoint()", "Toggle Breakpoint") +nmap_leader("dl", "lua require('dap').set_breakpoint(nil, nil, vim.fn.input('Log point: '))", "Log point") +nmap_leader("dc", "lua require('dap').continue()", "Run/Continue") +nmap_leader("dC", "lua require('dap').run_to_cursor()", "Run to Cursor") +nmap_leader("de", "lua require('dap.ui.widgets').hover()", "Inspect") +nmap_leader("dr", "lua require('dap').repl.open()", "Open REPL") +nmap_leader("dt", "lua require('dap').terminate()", "Terminate") -- Explore -leader("ed", function() MiniFiles.open() end, "Directory") -leader("ef", function() +local explore_at_file = function() local file = vim.api.nvim_buf_get_name(0) MiniFiles.open(vim.uv.fs_stat(file) and file or nil) -end, "File directory") -leader("ey", function() vim.fn.setreg("+", vim.api.nvim_buf_get_name(0)) end, "Yank absolute path") +end + +nmap_leader("ed", "lua MiniFiles.open()", "Directory") +nmap_leader("ef", explore_at_file, "File directory") +nmap_leader("ey", "lua vim.fn.setreg('+', vim.api.nvim_buf_get_name(0))", "Yank absolute path") +nmap_leader("en", "messages", "Notifications") -- Find -leader("fb", function() MiniPick.builtin.buffers() end, "Buffers") -leader("fc", function() MiniExtra.pickers.git_commits() end, "Commits (all)") -leader("fC", function() MiniExtra.pickers.git_commits({ path = "%" }) end, "Commits (buf)") -leader("fd", function() MiniExtra.pickers.diagnostic({ scope = "all" }) end, "Diagnostic workspace") -leader("fD", function() MiniExtra.pickers.diagnostic({ scope = "current" }) end, "Diagnostic buffer") -leader("ff", function() MiniPick.builtin.files() end, "Files") -leader("fg", function() MiniPick.builtin.grep_live() end, "Grep live") -leader("fG", function() MiniPick.builtin.grep({ pattern = vim.fn.expand("") }) end, "Grep word") -leader("fh", function() MiniPick.builtin.help() end, "Help tags") -leader("fl", function() MiniPick.builtin.buf_lines({ scope = "all" }) end, "Lines (all)") -leader("fL", function() MiniPick.builtin.buf_lines({ scope = "current" }) end, "Lines (buf)") -leader("fr", function() MiniPick.builtin.resume() end, "Resume") -leader("fs", function() MiniExtra.pickers.lsp({ scope = "workspace_symbol_live" }) end, "Symbols workspace") -leader("fS", function() MiniExtra.pickers.lsp({ scope = "document_symbol" }) end, "Symbols document") -leader("f:", function() MiniExtra.pickers.history({ scope = ":" }) end, "Command history") +nmap_leader("fb", "lua MiniPick.builtin.buffers()", "Buffers") +nmap_leader("fc", "lua MiniExtra.pickers.git_commits()", "Commits (all)") +nmap_leader("fC", "lua MiniExtra.pickers.git_commits({ path = '%' })", "Commits (buf)") +nmap_leader("fd", "lua MiniExtra.pickers.diagnostic({ scope = 'all' })", "Diagnostic workspace") +nmap_leader("fD", "lua MiniExtra.pickers.diagnostic({ scope = 'current' })", "Diagnostic buffer") +nmap_leader("ff", "lua MiniPick.builtin.files()", "Files") +nmap_leader("fg", "lua MiniPick.builtin.grep_live()", "Grep live") +nmap_leader("fG", "lua MiniPick.builtin.grep({ pattern = vim.fn.expand('') })", "Grep word") +nmap_leader("fh", "lua MiniPick.builtin.help()", "Help tags") +nmap_leader("fl", "lua MiniPick.builtin.buf_lines({ scope = 'all' })", "Lines (all)") +nmap_leader("fL", "lua MiniPick.builtin.buf_lines({ scope = 'current' })", "Lines (buf)") +nmap_leader("fr", "lua MiniPick.builtin.resume()", "Resume") +nmap_leader("fs", "lua MiniExtra.pickers.lsp({ scope = 'workspace_symbol_live' })", "Symbols workspace") +nmap_leader("fS", "lua MiniExtra.pickers.lsp({ scope = 'document_symbol' })", "Symbols document") +nmap_leader("f:", "lua MiniExtra.pickers.history({ scope = ':' })", "Command history") -- Git -leader("go", function() MiniDiff.toggle_overlay() end, "Toggle overlay") -leader("gs", function() MiniGit.show_at_cursor() end, "Show at cursor") -leader("gs", function() MiniGit.show_at_cursor() end, "Show selection", "x") +local git_log_cmd = [[Git log --pretty=format:\%h\ \%as\ │\ \%s --topo-order]] +local git_log_buf_cmd = git_log_cmd .. " --follow -- %" + +nmap_leader("ga", "Git diff --cached", "Added diff") +nmap_leader("gA", "Git diff --cached -- %", "Added diff buffer") +nmap_leader("gd", "Git diff", "Diff") +nmap_leader("gD", "Git diff -- %", "Diff buffer") +nmap_leader("gl", "" .. git_log_cmd .. "", "Log") +nmap_leader("gL", "" .. git_log_buf_cmd .. "", "Log buffer") +nmap_leader("go", "lua MiniDiff.toggle_overlay()", "Toggle overlay") +nmap_leader("gs", "lua MiniGit.show_at_cursor()", "Show at cursor") +xmap_leader("gs", "lua MiniGit.show_at_cursor()", "Show at selection") -- Language -leader("la", vim.lsp.buf.code_action, "Actions") -leader("ld", vim.diagnostic.open_float, "Diagnostic popup") -leader("lf", function() require("conform").format({ async = true }) end, "Format") -leader("lf", function() require("conform").format({ async = true }) end, "Format selection", "x") -leader("li", vim.lsp.buf.implementation, "Implementation") -leader("lh", vim.lsp.buf.hover, "Hover") -leader("ll", vim.lsp.codelens.run, "Lens") -leader("lr", vim.lsp.buf.rename, "Rename") -leader("lR", vim.lsp.buf.references, "References") -leader("ls", vim.lsp.buf.definition, "Source definition") -leader("lt", vim.lsp.buf.type_definition, "Type definition") +nmap_leader("la", "lua vim.lsp.buf.code_action()", "Actions") +nmap_leader("ld", "lua vim.diagnostic.open_float()", "Diagnostic popup") +nmap_leader("lf", "lua require('conform').format({ async = true })", "Format") +xmap_leader("lf", "lua require('conform').format({ async = true })", "Format selection") +nmap_leader("li", "lua vim.lsp.buf.implementation()", "Implementation") +nmap_leader("lh", "lua vim.lsp.buf.hover()", "Hover") +nmap_leader("ll", "lua vim.lsp.codelens.run()", "Lens") +nmap_leader("lr", "lua vim.lsp.buf.rename()", "Rename") +nmap_leader("lR", "lua vim.lsp.buf.references()", "References") +nmap_leader("ls", "lua vim.lsp.buf.definition()", "Source definition") +nmap_leader("lt", "lua vim.lsp.buf.type_definition()", "Type definition") -- Request -leader("rs", function() require("kulala").run() end, "Send HTTP request") +nmap_leader("rs", "lua require('kulala').run()", "Send HTTP request") -- Session -leader("sd", function() MiniSessions.select("delete") end, "Delete") -leader("sn", function() vim.ui.input({ prompt = "Session name: " }, MiniSessions.write) end, "New") -leader("sr", function() MiniSessions.select("read") end, "Read") -leader("sR", function() MiniSessions.restart() end, "Restart") -leader("sw", function() MiniSessions.write() end, "Write current") +local session_new = "vim.ui.input({ prompt = 'Session name: ' }, MiniSessions.write)" + +nmap_leader("sd", "lua MiniSessions.select('delete')", "Delete") +nmap_leader("sn", "lua " .. session_new .. "", "New") +nmap_leader("sr", "lua MiniSessions.select('read')", "Read") +nmap_leader("sR", "lua MiniSessions.restart()", "Restart") +nmap_leader("sw", "lua MiniSessions.write()", "Write current") -- Terminal -leader("tT", "horizontal term", "Terminal (horizontal)") -leader("tt", "vertical term", "Terminal (vertical)") -leader("tc", "vertical term claude", "Claude") -leader("tf", function() require("terminal").open_terminal_app("bash") end, "Terminal (popup)") -leader("tg", function() require("terminal").open_terminal_app("lazygit") end, "LazyGit") -leader("ts", function() require("terminal").open_terminal_app("lazysql") end, "LazySQL") +nmap_leader("tT", "horizontal term", "Terminal (horizontal)") +nmap_leader("tt", "vertical term", "Terminal (vertical)") +nmap_leader("tc", "vertical term claude", "Claude") +nmap_leader("tf", "lua require('terminal').open_terminal_app('bash')", "Terminal (popup)") +nmap_leader("tg", "lua require('terminal').open_terminal_app('lazygit')", "LazyGit") +nmap_leader("ts", "lua require('terminal').open_terminal_app('lazysql')", "LazySQL") -- Overwrites -map("n", "", "nohlsearch", "Clear highlights") -map("t", "", "", "Terminal window navigation") +vim.keymap.set("n", "", "nohlsearch", { desc = "Clear highlights", silent = true }) +vim.keymap.set("t", "", "", { desc = "Terminal window navigation", silent = true }) diff --git a/plugin/30_mini.lua b/plugin/30_mini.lua index a993fe0..387050c 100644 --- a/plugin/30_mini.lua +++ b/plugin/30_mini.lua @@ -48,6 +48,7 @@ end) -- Editing & Navigation Config.later(function() require('mini.ai').setup() + require('mini.pairs').setup() require('mini.surround').setup() require('mini.pick').setup() require('mini.bracketed').setup() @@ -65,7 +66,7 @@ Config.now_if_args(function() end) -- Completion -Config.later(function() +Config.now_if_args(function() require('mini.completion').setup({ lsp_completion = { source_func = 'omnifunc', diff --git a/plugin/40_plugins.lua b/plugin/40_plugins.lua index fa5708e..94dcf11 100644 --- a/plugin/40_plugins.lua +++ b/plugin/40_plugins.lua @@ -10,7 +10,6 @@ end) -- Treesitter Config.now_if_args(function() vim.pack.add({ 'https://github.com/nvim-treesitter/nvim-treesitter' }) - vim.treesitter.language.register('tsx', { 'typescriptreact' }) local filetypes = { 'html', 'css', 'lua', 'go', 'php', 'blade', 'sql', 'javascript',