diff --git a/doc/fzf-lua.txt b/doc/fzf-lua.txt index d5681439..9a41d160 100644 --- a/doc/fzf-lua.txt +++ b/doc/fzf-lua.txt @@ -1,4 +1,4 @@ -*fzf-lua.txt* For Neovim >= 0.5.0 Last change: 2023 October 04 +*fzf-lua.txt* For Neovim >= 0.5.0 Last change: 2023 October 07 ============================================================================== Table of Contents *fzf-lua-table-of-contents* @@ -409,7 +409,6 @@ COMPLETION FUNCTIONS *fzf-lua-completion-functions* | Command | List | | -------------------- | ------------------------------------------ | -| `fzf_complete` | custom completion (see below) | | `complete_path` | complete path under cursor (incl dirs) | | `complete_file` | complete file under cursor (excl dirs) | | `complete_line` | complete line (all open buffers) | @@ -536,11 +535,35 @@ Or with a custom command and preview: CUSTOM COMPLETION *fzf-lua-custom-completion* -Custom completion is also possible using `fzf_complete`, the signature for -`fzf_complete` is equivalent to `fzf_exec = function(contents, [opts])`, for -more info how to use the API, please refer to Wiki/ADVANCED -. +Every fzf-lua function can be easily converted to a completion function by +sending `complete = true` in the options: + By default fzf-lua will insert the entry at the cursor location as if you used + `p` to paste the selected entry. + +>lua + require("fzf-lua").fzf_exec({"foo", "bar"}, {complete = true}) +< +Custom completion is possible using a custom completion callback, the example +below will replace the text from the current cursor column with the selected +entry: + +>lua + require("fzf-lua").fzf_exec({"foo", "bar"}, { + -- @param selected: the selected entry or entries + -- @param opts: fzf-lua caller/provider options + -- @param line: originating buffer completed line + -- @param col: originating cursor column location + -- @return newline: will replace the current buffer line + -- @return newcol?: optional, sets the new cursor column + complete = function(selected, opts, line, col) + local newline = line:sub(1, col) .. selected[1] + -- set cursor to EOL, since `nvim_win_set_cursor` + -- is 0-based we have to lower the col value by 1 + return newline, #newline - 1 + end + }) +< DEFAULT OPTIONS *fzf-lua-default-options* @@ -1235,7 +1258,7 @@ open an issue and I'll be more than happy to help.** }, complete_path = { cmd = nil, -- default: auto detect fd|rg|find - actions = { ["default"] = actions.complete_insert }, + complete = { ["default"] = actions.complete }, }, complete_file = { cmd = nil, -- default: auto detect rg|fd|find @@ -1243,7 +1266,7 @@ open an issue and I'll be more than happy to help.** color_icons = true, git_icons = false, -- actions inherit from 'actions.files' and merge - actions = { ["default"] = actions.complete_insert }, + actions = { ["default"] = actions.complete }, -- previewer hidden by default winopts = { preview = { hidden = "hidden" } }, },