mirror of
https://github.com/Baipyrus/nvim-config.git
synced 2024-12-26 13:21:45 +00:00
match lines based on input expr
This commit is contained in:
parent
ae7799c6bc
commit
854eaaef90
@ -81,6 +81,9 @@ local function get_visual_selection()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function global_cmd_yank()
|
local function global_cmd_yank()
|
||||||
|
-- Prompt user input for expression
|
||||||
|
local inexpr = vim.fn.input 'Enter expression: '
|
||||||
|
|
||||||
-- Get the (selected) lines
|
-- Get the (selected) lines
|
||||||
local lines = nil
|
local lines = nil
|
||||||
local mode = vim.api.nvim_get_mode()['mode']
|
local mode = vim.api.nvim_get_mode()['mode']
|
||||||
@ -89,6 +92,12 @@ local function global_cmd_yank()
|
|||||||
else
|
else
|
||||||
lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
vim.keymap.set({ 'n', 'v' }, '<leader>gy', global_cmd_yank, { desc = '[G]lobal command [Y]ank' })
|
vim.keymap.set({ 'n', 'v' }, '<leader>gy', global_cmd_yank, { desc = '[G]lobal command [Y]ank' })
|
||||||
|
Loading…
Reference in New Issue
Block a user