From 6806aa79776509dc578b53d90259d2637fc732e5 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Wed, 3 Jul 2024 12:41:21 +0200 Subject: [PATCH] match lines based on input expr --- lua/keymaps.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lua/keymaps.lua b/lua/keymaps.lua index 88b0df0..55c2df2 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -81,6 +81,9 @@ local function get_visual_selection() end local function global_cmd_yank() + -- Prompt user input for expression + local inexpr = vim.fn.input 'Enter expression: ' + -- Get the (selected) lines local lines = nil local mode = vim.api.nvim_get_mode()['mode'] @@ -89,6 +92,12 @@ local function global_cmd_yank() else lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) end + + -- Apply expression on all lines + local matches = vim.fn.matchstrlist(lines, inexpr) + local extracted = vim.tbl_map(function(value) + return value['text'] + end, matches) end vim.keymap.set({ 'n', 'v' }, 'gy', global_cmd_yank, { desc = '[G]lobal command [Y]ank' })