diff --git a/README.md b/README.md index 9b9feb3..1368887 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,11 @@ Consult the list below for available settings: local actions = require "fzf-lua.actions" require'fzf-lua'.setup { winopts = { - -- split = "new", -- open in a split instead? + -- split = "belowright new",-- open in a split instead? + -- "belowright new" : split below + -- "aboveleft new" : split above + -- "belowright vnew" : split right + -- "aboveleft vnew : split left win_height = 0.85, -- window height win_width = 0.80, -- window width win_row = 0.30, -- window row position (0=top, 1=bottom) @@ -459,6 +463,11 @@ require'fzf-lua'.setup { -- uncomment to disable the previewer -- helptags = { previewer = { _new = false } }, -- manpages = { previewer = { _new = false } }, + -- uncomment to set dummy win location (help|man bar) + -- "topleft" : up + -- "botright" : down + -- helptags = { previewer = { split = "topleft" } }, + -- manpages = { previewer = { split = "topleft" } }, -- uncomment 2 lines to use `man` command as native fzf previewer -- manpages = { previewer = { cmd = "man", _new = function() -- return require 'fzf-lua.previewer'.man_pages end } }, diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index 7499571..f27b337 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -21,14 +21,13 @@ M.fzf = function(opts, contents) if preview_opts and type(preview_opts._new) == 'function' then previewer = preview_opts._new()(preview_opts, opts, fzf_win) opts.preview = previewer:cmdline() - if type(previewer.override_fzf_preview_window) == 'function' then + if type(previewer.preview_window) == 'function' then -- do we need to override the preview_window args? -- this can happen with the builtin previewer -- (1) when using a split we use the previewer as placeholder - -- (2) we use 'right:0' to call the previewer function only - if previewer:override_fzf_preview_window() then - opts.preview_window = previewer:preview_window() - end + -- (2) we use 'nohidden:right:0' to trigger preview function + -- calls without displaying the native fzf previewer split + opts.preview_window = previewer:preview_window(opts.preview_window) end end diff --git a/lua/fzf-lua/init.lua b/lua/fzf-lua/init.lua index 279a834..68da4c6 100644 --- a/lua/fzf-lua/init.lua +++ b/lua/fzf-lua/init.lua @@ -42,7 +42,7 @@ M.fzf_files = require'fzf-lua.core'.fzf_files M.files = require'fzf-lua.providers.files'.files M.files_resume = require'fzf-lua.providers.files'.files_resume M.grep = require'fzf-lua.providers.grep'.grep -M.live_grep = require'fzf-lua.providers.grep'.live_grep +M.live_grep = require'fzf-lua.providers.grep'.live_grep_resume M.live_grep_native = require'fzf-lua.providers.grep'.live_grep_native M.live_grep_resume = require'fzf-lua.providers.grep'.live_grep_resume M.grep_last = require'fzf-lua.providers.grep'.grep_last diff --git a/lua/fzf-lua/previewer/builtin.lua b/lua/fzf-lua/previewer/builtin.lua index 992d579..236555f 100644 --- a/lua/fzf-lua/previewer/builtin.lua +++ b/lua/fzf-lua/previewer/builtin.lua @@ -197,11 +197,11 @@ function Previewer.base:cmdline(_) end function Previewer.base:preview_window(_) - return 'nohidden:right:0' -end - -function Previewer.base:override_fzf_preview_window() - return self.win and not self.win.winopts.split + if self.win and not self.win.winopts.split then + return 'nohidden:right:0' + else + return nil + end end function Previewer.base.scroll(direction) @@ -447,6 +447,8 @@ function Previewer.help_tags:new(o, opts, fzf_win) __index = vim.tbl_deep_extend("keep", self, Previewer.base )}) + self.split = o.split + self.help_cmd = o.help_cmd or "help" self:init_help_win() return self end @@ -468,7 +470,7 @@ end function Previewer.help_tags:exec_cmd(str) str = str or '' - vim.cmd("help " .. str) + vim.cmd(("%s %s %s"):format(self.split, self.help_cmd, str)) end function Previewer.help_tags:parse_entry(entry_str) @@ -476,11 +478,17 @@ function Previewer.help_tags:parse_entry(entry_str) end function Previewer.help_tags:init_help_win(str) + if not self.split or + (self.split ~= "topleft" and self.split ~= "botright") then + self.split = "botright" + end + local orig_winid = api.nvim_get_current_win() self:exec_cmd(str) self.help_bufnr = api.nvim_get_current_buf() self.help_winid = api.nvim_get_current_win() pcall(vim.api.nvim_win_set_height, 0, 0) pcall(vim.api.nvim_win_set_width, 0, 0) + api.nvim_set_current_win(orig_winid) end function Previewer.help_tags:populate_preview_buf(entry_str) @@ -528,15 +536,12 @@ function Previewer.man_pages:new(o, opts, fzf_win) __index = vim.tbl_deep_extend("keep", self, Previewer.help_tags, Previewer.base )}) + self.split = o.split + self.help_cmd = o.help_cmd or "Man" self:init_help_win("echo") return self end -function Previewer.man_pages:exec_cmd(str) - str = str or '' - vim.cmd("Man " .. str) -end - function Previewer.man_pages:parse_entry(entry_str) return entry_str:match("[^[,( ]+") -- return require'fzf-lua.providers.manpages'.getmanpage(entry_str) diff --git a/lua/fzf-lua/previewer/init.lua b/lua/fzf-lua/previewer/init.lua index 0671df5..84b7a03 100644 --- a/lua/fzf-lua/previewer/init.lua +++ b/lua/fzf-lua/previewer/init.lua @@ -35,6 +35,10 @@ function Previewer.base:new(o, opts) return self end +function Previewer.base:preview_window(_) + return nil +end + -- Generic shell command previewer function Previewer.cmd:new(o, opts) self = setmetatable(Previewer.base(o, opts), { @@ -210,12 +214,4 @@ function Previewer.man_pages:cmdline(o) return act end -function Previewer.man_pages:override_fzf_preview_window() - return true -end - -function Previewer.man_pages:preview_window(_) - return nil -end - return Previewer diff --git a/lua/fzf-lua/providers/grep.lua b/lua/fzf-lua/providers/grep.lua index 216c00f..ed8506a 100644 --- a/lua/fzf-lua/providers/grep.lua +++ b/lua/fzf-lua/providers/grep.lua @@ -261,7 +261,10 @@ end M.live_grep_resume = function(opts) if not opts then opts = {} end - opts.continue_last_search = true + opts.continue_last_search = + (opts.continue_last_search == nil and + opts.repeat_last_search == nil and true) or + (opts.continue_last_search or opts.repeat_last_search) return M.live_grep(opts) end diff --git a/lua/fzf-lua/providers/helptags.lua b/lua/fzf-lua/providers/helptags.lua index 198dfc6..dc690be 100644 --- a/lua/fzf-lua/providers/helptags.lua +++ b/lua/fzf-lua/providers/helptags.lua @@ -104,9 +104,9 @@ M.helptags = function(opts) -- local prev_act = action(function (args) end) + opts.nomulti = true + opts.preview_window = 'hidden:right:0' opts._fzf_cli_args = "--nth 1" - opts.preview_window = opts.preview_window or 'right:0' - opts.nomulti = utils._if(opts.nomulti~=nil, opts.nomulti, true) local selected = core.fzf(opts, fzf_function)