junegunn / junegunn/fzf.vim

Use selected text to fill initial query on popup

Open
#1,603 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vim Script
Stars
10.3k
Forks
608
Avg merge
5d 8h
Merged PRs (30d)
2

Description

I search around for a working example and didn't find anything

```
function! FzfFilesWithVisualPrefilter() range
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
let lines = getline(lnum1, lnum2)
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][col1 - 1:]

let prefilter = lines[0]
call fzf#vim#files('', fzf#vim#with_preview({ 'options': '--query "' . prefilter . '"'}))
"call fzf#vim#files('', fzf#vim#with_preview({'options': {'query': prefilter}}))
endfunction

xnoremap ff :call FzfFilesWithVisualPrefilter()
```

select a text, press `,ff` and you have a popup searching for files matching your selected text.

Wonder if:

Is there a helper to get selected text for fzf.vim?

Should a line like:

```
call fzf#vim#files('', fzf#vim#with_preview({'options': {'query': prefilter}}))
```

work. Searching for a cleaner way to compose `--query` line

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.