Skip to content

Commit 675820b

Browse files
scticeibhagwan
authored andcommitted
feat: add word_pattern option for completion
1 parent 15d5cd9 commit 675820b

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

OPTIONS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,10 +1229,22 @@ Zoxide recent directories
12291229

12301230
Complete path under cursor (incl dirs)
12311231

1232+
##### complete_path.word_pattern
1233+
1234+
Type: `string`, Default: `nil`
1235+
1236+
The pattern used to match the word under the cursor. Text around the cursor position that matches will be used as the initial query and replaced by a chosen completion. The default matches anything but spaces and single/double quotes.
1237+
12321238
#### complete_file
12331239

12341240
Complete file under cursor (excl dirs)
12351241

1242+
##### complete_file.word_pattern
1243+
1244+
Type: `string`, Default: `nil`
1245+
1246+
See [`complete_path.word_pattern`](#complete_path.word_pattern)
1247+
12361248
#### complete_line
12371249

12381250
Complete line (all open buffers)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,11 +1262,13 @@ previewers = {
12621262
complete_path = {
12631263
cmd = nil, -- default: auto detect fd|rg|find
12641264
complete = { ["enter"] = actions.complete },
1265+
word_pattern = nil, -- default: "[^%s\"']*"
12651266
},
12661267
complete_file = {
12671268
cmd = nil, -- default: auto detect rg|fd|find
12681269
file_icons = true,
12691270
color_icons = true,
1271+
word_pattern = nil,
12701272
-- actions inherit from 'actions.files' and merge
12711273
actions = { ["enter"] = actions.complete },
12721274
-- previewer hidden by default

doc/fzf-lua-opts.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,12 +1693,29 @@ complete_path *fzf-lua-opts-complete_path*
16931693
Complete path under cursor (incl dirs)
16941694

16951695

1696+
complete_path.word_pattern *fzf-lua-opts-complete_path.word_pattern*
1697+
1698+
Type: `string`, Default: `nil`
1699+
1700+
The pattern used to match the word under the cursor. Text around the cursor
1701+
position that matches will be used as the initial query and replaced by a
1702+
chosen completion. The default matches anything but spaces and single/double
1703+
quotes.
1704+
1705+
16961706

16971707
complete_file *fzf-lua-opts-complete_file*
16981708

16991709
Complete file under cursor (excl dirs)
17001710

17011711

1712+
complete_file.word_pattern *fzf-lua-opts-complete_file.word_pattern*
1713+
1714+
Type: `string`, Default: `nil`
1715+
1716+
See |fzf-lua-opts-complete_path.word_pattern|.
1717+
1718+
17021719

17031720
complete_line *fzf-lua-opts-complete_line*
17041721

@@ -1711,4 +1728,4 @@ complete_bline *fzf-lua-opts-complete_bline*
17111728
Complete line (current buffer only)
17121729

17131730

1714-
vim:tw=78:ts=8:ft=help:norl:
1731+
vim:tw=78:ts=8:ft=help:norl:

lua/fzf-lua/complete.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ end
4848
-- set the cwd and prompt top the top level directory and
4949
-- the leftover match to the input query
5050
local set_cmp_opts_path = function(opts)
51-
local match = "[^%s\"']*"
51+
local match = opts.word_pattern or "[^%s\"']*"
5252
local line = vim.api.nvim_get_current_line()
5353
local col = vim.api.nvim_win_get_cursor(0)[2] + 1
5454
local before = col > 1 and line:sub(1, col - 1):reverse():match(match):reverse() or ""

lua/fzf-lua/defaults.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ M.defaults.complete_path = {
11381138
git_icons = false,
11391139
color_icons = true,
11401140
multiprocess = true,
1141+
word_pattern = nil,
11411142
fzf_opts = { ["--no-multi"] = true },
11421143
_fzf_nth_devicons = true,
11431144
actions = { ["enter"] = actions.complete },
@@ -1149,6 +1150,7 @@ M.defaults.complete_file = {
11491150
file_icons = 1,
11501151
color_icons = true,
11511152
git_icons = false,
1153+
word_pattern = nil,
11521154
_actions = function() return M.globals.actions.files end,
11531155
actions = { ["enter"] = actions.complete },
11541156
previewer = M._default_previewer_fn,

0 commit comments

Comments
 (0)