diff --git a/README.md b/README.md index 4ef1524..3702963 100644 --- a/README.md +++ b/README.md @@ -334,6 +334,29 @@ require'fzf-lua'.setup { ["shift-up"] = "preview-page-up", }, }, + actions = { + -- These override the default tables completely + -- no need to set to `false` to disable an action + -- delete or modify is sufficient + files = { + -- default action opens a single selection + -- or sends multiple selection to quickfix + -- replace the default action with the below + -- to open all files whether single or multiple + -- ["default"] = actions.file_edit, + ["default"] = actions.file_edit_or_qf, + ["ctrl-s"] = actions.file_split, + ["ctrl-v"] = actions.file_vsplit, + ["ctrl-t"] = actions.file_tabedit, + ["alt-q"] = actions.file_sel_to_qf, + }, + buffers = { + ["default"] = actions.buf_edit, + ["ctrl-s"] = actions.buf_split, + ["ctrl-v"] = actions.buf_vsplit, + ["ctrl-t"] = actions.buf_tabedit, + } + }, fzf_opts = { -- options are sent as `=` -- set to `false` to remove a flag @@ -410,17 +433,9 @@ require'fzf-lua'.setup { rg_opts = "--color=never --files --hidden --follow -g '!.git'", fd_opts = "--color=never --type f --hidden --follow --exclude .git", actions = { - -- set bind to 'false' to disable an action - -- default action opens a single selection - -- or sends multiple selection to quickfix - -- replace the default action with the below - -- to open all files whether single or multiple - -- ["default"] = actions.file_edit, - ["default"] = actions.file_edit_or_qf, - ["ctrl-s"] = actions.file_split, - ["ctrl-v"] = actions.file_vsplit, - ["ctrl-t"] = actions.file_tabedit, - ["alt-q"] = actions.file_sel_to_qf, + -- inherits from 'actions.files', here we can override + -- or set bind to 'false' to disable a default action + ["default"] = actions.file_edit, -- custom actions are available too ["ctrl-y"] = function(selected) print(selected[1]) end, } @@ -445,13 +460,9 @@ require'fzf-lua'.setup { git_icons = true, color_icons = true, actions = { - ["default"] = actions.file_edit_or_qf, - ["ctrl-s"] = actions.file_split, - ["ctrl-v"] = actions.file_vsplit, - ["ctrl-t"] = actions.file_tabedit, - ["alt-q"] = actions.file_sel_to_qf, - ["right"] = { actions.git_unstage, actions.resume }, - ["left"] = { actions.git_stage, actions.resume }, + -- actions inherit from 'actions.files' and merge + ["right"] = { actions.git_unstage, actions.resume }, + ["left"] = { actions.git_stage, actions.resume }, }, }, commits = { @@ -514,7 +525,7 @@ require'fzf-lua'.setup { args = { prompt = 'Args❯ ', files_only = true, - -- added on top of regular file actions + -- actions inherit from 'actions.files' and merge actions = { ["ctrl-x"] = actions.arg_del } }, oldfiles = { @@ -527,10 +538,7 @@ require'fzf-lua'.setup { color_icons = true, -- colorize file|git icons sort_lastused = true, -- sort buffers() by last used actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, + -- actions inherit from 'actions.buffers' and merge -- by supplying a table of functions we're telling -- fzf-lua to not close the fzf window, this way we -- can resume the buffers picker on the same window @@ -550,12 +558,7 @@ require'fzf-lua'.setup { ["--nth"] = '2..', ["--tiebreak"] = 'index', }, - actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, - } + -- actions inherit from 'actions.buffers' }, blines = { previewer = "builtin", -- set to 'false' to disable @@ -568,12 +571,7 @@ require'fzf-lua'.setup { ["--with-nth"] = '2..', ["--tiebreak"] = 'index', }, - actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, - } + -- actions inherit from 'actions.buffers' }, colorschemes = { prompt = 'Colorschemes❯ ', diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index 00872ec..63618a2 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -373,6 +373,29 @@ Consult the list below for available settings: ["shift-up"] = "preview-page-up", }, }, + actions = { + -- These override the default tables completely + -- no need to set to `false` to disable an action + -- delete or modify is sufficient + files = { + -- default action opens a single selection + -- or sends multiple selection to quickfix + -- replace the default action with the below + -- to open all files whether single or multiple + -- ["default"] = actions.file_edit, + ["default"] = actions.file_edit_or_qf, + ["ctrl-s"] = actions.file_split, + ["ctrl-v"] = actions.file_vsplit, + ["ctrl-t"] = actions.file_tabedit, + ["alt-q"] = actions.file_sel_to_qf, + }, + buffers = { + ["default"] = actions.buf_edit, + ["ctrl-s"] = actions.buf_split, + ["ctrl-v"] = actions.buf_vsplit, + ["ctrl-t"] = actions.buf_tabedit, + } + }, fzf_opts = { -- options are sent as `=` -- set to `false` to remove a flag @@ -449,17 +472,9 @@ Consult the list below for available settings: rg_opts = "--color=never --files --hidden --follow -g '!.git'", fd_opts = "--color=never --type f --hidden --follow --exclude .git", actions = { - -- set bind to 'false' to disable an action - -- default action opens a single selection - -- or sends multiple selection to quickfix - -- replace the default action with the below - -- to open all files whether single or multiple - -- ["default"] = actions.file_edit, - ["default"] = actions.file_edit_or_qf, - ["ctrl-s"] = actions.file_split, - ["ctrl-v"] = actions.file_vsplit, - ["ctrl-t"] = actions.file_tabedit, - ["alt-q"] = actions.file_sel_to_qf, + -- inherits from 'actions.files', here we can override + -- or set bind to 'false' to disable a default action + ["default"] = actions.file_edit, -- custom actions are available too ["ctrl-y"] = function(selected) print(selected[1]) end, } @@ -484,13 +499,9 @@ Consult the list below for available settings: git_icons = true, color_icons = true, actions = { - ["default"] = actions.file_edit_or_qf, - ["ctrl-s"] = actions.file_split, - ["ctrl-v"] = actions.file_vsplit, - ["ctrl-t"] = actions.file_tabedit, - ["alt-q"] = actions.file_sel_to_qf, - ["right"] = { actions.git_unstage, actions.resume }, - ["left"] = { actions.git_stage, actions.resume }, + -- actions inherit from 'actions.files' and merge + ["right"] = { actions.git_unstage, actions.resume }, + ["left"] = { actions.git_stage, actions.resume }, }, }, commits = { @@ -553,7 +564,7 @@ Consult the list below for available settings: args = { prompt = 'Args❯ ', files_only = true, - -- added on top of regular file actions + -- actions inherit from 'actions.files' and merge actions = { ["ctrl-x"] = actions.arg_del } }, oldfiles = { @@ -566,10 +577,7 @@ Consult the list below for available settings: color_icons = true, -- colorize file|git icons sort_lastused = true, -- sort buffers() by last used actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, + -- actions inherit from 'actions.buffers' and merge -- by supplying a table of functions we're telling -- fzf-lua to not close the fzf window, this way we -- can resume the buffers picker on the same window @@ -589,12 +597,7 @@ Consult the list below for available settings: ["--nth"] = '2..', ["--tiebreak"] = 'index', }, - actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, - } + -- actions inherit from 'actions.buffers' }, blines = { previewer = "builtin", -- set to 'false' to disable @@ -607,12 +610,7 @@ Consult the list below for available settings: ["--with-nth"] = '2..', ["--tiebreak"] = 'index', }, - actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, - } + -- actions inherit from 'actions.buffers' }, colorschemes = { prompt = 'Colorschemes❯ ', diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 3ed50a3..1f3d500 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -112,6 +112,21 @@ M.globals = { ["shift-up"] = "preview-page-up", }, }, + actions = { + files = { + ["default"] = actions.file_edit_or_qf, + ["ctrl-s"] = actions.file_split, + ["ctrl-v"] = actions.file_vsplit, + ["ctrl-t"] = actions.file_tabedit, + ["alt-q"] = actions.file_sel_to_qf, + }, + buffers = { + ["default"] = actions.buf_edit, + ["ctrl-s"] = actions.buf_split, + ["ctrl-v"] = actions.buf_vsplit, + ["ctrl-t"] = actions.buf_tabedit, + } + }, fzf_bin = nil, fzf_opts = { ['--ansi'] = '', @@ -175,13 +190,7 @@ M.globals.files = { find_opts = [[-type f -not -path '*/\.git/*' -printf '%P\n']], rg_opts = "--color=never --files --hidden --follow -g '!.git'", fd_opts = "--color=never --type f --hidden --follow --exclude .git", - actions = { - ["default"] = actions.file_edit_or_qf, - ["ctrl-s"] = actions.file_split, - ["ctrl-v"] = actions.file_vsplit, - ["ctrl-t"] = actions.file_tabedit, - ["alt-q"] = actions.file_sel_to_qf, - }, + _actions = function() return M.globals.actions.files end, } -- Must construct our opts table in stages -- so we can reference 'M.globals.files' @@ -194,7 +203,7 @@ M.globals.git = { file_icons = true and M._has_devicons, color_icons = true, git_icons = true, - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, }, status = { prompt = 'GitStatus> ', @@ -203,14 +212,10 @@ M.globals.git = { file_icons = true and M._has_devicons, color_icons = true, git_icons = true, + _actions = function() return M.globals.actions.files end, actions = { - ["default"] = actions.file_edit_or_qf, - ["ctrl-s"] = actions.file_split, - ["ctrl-v"] = actions.file_vsplit, - ["ctrl-t"] = actions.file_tabedit, - ["alt-q"] = actions.file_sel_to_qf, - ["right"] = { actions.git_unstage, actions.resume }, - ["left"] = { actions.git_stage, actions.resume }, + ["right"] = { actions.git_unstage, actions.resume }, + ["left"] = { actions.git_stage, actions.resume }, }, }, commits = { @@ -260,7 +265,7 @@ M.globals.grep = { git_icons = true, grep_opts = "--binary-files=without-match --line-number --recursive --color=auto --perl-regexp", rg_opts = "--column --line-number --no-heading --color=always --smart-case --max-columns=512", - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, -- live_grep_glob options glob_flag = "--iglob", -- for case sensitive globs use '--glob' glob_separator = "%s%-%-", -- query separator pattern (lua): ' --' @@ -272,16 +277,18 @@ M.globals.args = { file_icons = true and M._has_devicons, color_icons = true, git_icons = true, - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, + actions = { + ["ctrl-x"] = actions.arg_del + }, } -M.globals.args.actions["ctrl-x"] = actions.arg_del M.globals.oldfiles = { previewer = M._default_previewer_fn, prompt = 'History> ', file_icons = true and M._has_devicons, color_icons = true, git_icons = false, - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, } M.globals.quickfix = { previewer = M._default_previewer_fn, @@ -290,7 +297,7 @@ M.globals.quickfix = { file_icons = true and M._has_devicons, color_icons = true, git_icons = false, - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, } M.globals.loclist = { previewer = M._default_previewer_fn, @@ -299,7 +306,7 @@ M.globals.loclist = { file_icons = true and M._has_devicons, color_icons = true, git_icons = false, - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, } M.globals.buffers = { previewer = "builtin", @@ -310,11 +317,8 @@ M.globals.buffers = { show_all_buffers = true, ignore_current_buffer = false, cwd_only = false, + _actions = function() return M.globals.actions.buffers end, actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, ["ctrl-x"] = { actions.buf_del, actions.resume }, }, } @@ -325,11 +329,9 @@ M.globals.tabs = { tab_marker = "<<", file_icons = true and M._has_devicons, color_icons = true, + _actions = function() return M.globals.actions.buffers end, actions = { ["default"] = actions.buf_switch, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, ["ctrl-x"] = { actions.buf_del, actions.resume }, }, } @@ -345,12 +347,7 @@ M.globals.lines = { ["--nth"] = '2..', ["--tiebreak"] = 'index', }, - actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, - }, + _actions = function() return M.globals.actions.buffers end, } M.globals.blines = { previewer = "builtin", @@ -364,12 +361,7 @@ M.globals.blines = { ["--with-nth"] = '2..', ["--tiebreak"] = 'index', }, - actions = { - ["default"] = actions.buf_edit, - ["ctrl-s"] = actions.buf_split, - ["ctrl-v"] = actions.buf_vsplit, - ["ctrl-t"] = actions.buf_tabedit, - }, + _actions = function() return M.globals.actions.buffers end, } M.globals.tags = { previewer = { _ctor = previewers.builtin.tags }, @@ -378,7 +370,7 @@ M.globals.tags = { file_icons = true and M._has_devicons, git_icons = true, color_icons = true, - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, } M.globals.btags = { previewer = { _ctor = previewers.builtin.tags }, @@ -387,7 +379,7 @@ M.globals.btags = { file_icons = true and M._has_devicons, git_icons = true, color_icons = true, - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, } M.globals.colorschemes = { prompt = 'Colorschemes> ', @@ -432,7 +424,7 @@ M.globals.lsp = { lsp_icons = true, cwd_only = false, async_or_timeout = 5000, - actions = M.globals.files.actions, + _actions = function() return M.globals.actions.files end, icons = { ["Error"] = { icon = "", color = "red" }, -- error ["Warning"] = { icon = "", color = "yellow" }, -- warning @@ -583,6 +575,13 @@ function M.normalize_opts(opts, defaults) opts = opts() end + -- inherit from globals.actions? + if type(defaults._actions) == 'function' then + defaults.actions = vim.tbl_deep_extend("keep", + defaults.actions or {}, + defaults._actions()) + end + -- First, merge with provider defaults -- we must clone the 'defaults' tbl, otherwise 'opts.actions.default' -- overrides 'config.globals.lsp.actions.default' in neovim 6.0 diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index aeffe54..5668a5c 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -50,6 +50,13 @@ function M.setup(opts) if opts.keymap and opts.keymap.builtin then globals.keymap.builtin = opts.keymap.builtin end + -- do not merge, override the default action tables + if opts.actions and opts.actions.files then + globals.actions.files = opts.actions.files + end + if opts.actions and opts.actions.buffers then + globals.actions.buffers = opts.actions.buffers + end -- deprecated options if globals.previewers.builtin.keymap then utils.warn("'previewers.builtin.keymap' moved under 'keymap.builtin', see ':help fzf-lua-customization'")