diff --git a/home/programs/nvf/keymaps.nix b/home/programs/nvf/keymaps.nix index 0f5cc64..b708c1b 100644 --- a/home/programs/nvf/keymaps.nix +++ b/home/programs/nvf/keymaps.nix @@ -1,6 +1,7 @@ { vim = { globals.mapleader = " "; + keymaps = [ { key = "s"; @@ -144,6 +145,52 @@ desc = "Todo (Trouble)"; } + # Shell + { + key = "!"; + mode = "n"; + silent = true; + lua = true; + desc = "Insert command output"; + action = '' + function() + local cmd = vim.fn.input("Command: ") + if cmd == "" then return end + local lines = vim.fn.systemlist(cmd) + while #lines > 0 and lines[#lines] == "" do + table.remove(lines) + end + if #lines == 0 then return end + vim.api.nvim_put(lines, "l", true, true) + end + ''; + } + { + key = "!"; + mode = "v"; + silent = true; + lua = true; + desc = "Run command with selection"; + action = '' + function() + local start_line = vim.fn.line("'<") + local end_line = vim.fn.line("'>") + local lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false) + local input_text = table.concat(lines, "\n") + + local cmd = vim.fn.input("$ ") + if cmd == "" then return end + + local result = vim.fn.system({"bash", "-c", cmd}, input_text) + local output = vim.split(result, "\n", { plain = true }) + if output[#output] == "" then table.remove(output) end + if #output == 0 then return end + + vim.api.nvim_buf_set_lines(0, start_line - 1, end_line, false, output) + end + ''; + } + # QOL { key = ">"; diff --git a/home/programs/nvf/languages.nix b/home/programs/nvf/languages.nix index e447641..efc96f3 100644 --- a/home/programs/nvf/languages.nix +++ b/home/programs/nvf/languages.nix @@ -24,6 +24,7 @@ autotagHtml = true; context.enable = true; highlight.enable = true; + textobjects.enable = true; }; lsp = { enable = true; diff --git a/home/programs/nvf/mini.nix b/home/programs/nvf/mini.nix index ac4d075..2814a87 100644 --- a/home/programs/nvf/mini.nix +++ b/home/programs/nvf/mini.nix @@ -27,6 +27,8 @@ { mode = 'n', keys = 'u', desc = '+ui' }, { mode = 'n', keys = 'l', desc = '+lsp' }, { mode = 'n', keys = 'x', desc = '+trouble' }, + { mode = 'n', keys = '!', desc = 'shell' }, + { mode = 'v', keys = '!', desc = 'shell' }, }, window = { delay = 300 }, }) @@ -44,5 +46,6 @@ jump2d.enable = true; statusline.enable = true; clue.enable = true; + surround.enable = true; }; }