Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fzf-lua support #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ Thus, the intention of this plugin is to bring the best of both worlds to your f

Install using [vim-plug](https://github.com/junegunn/vim-plug) or similar:

```
```vim
Plug 'jesseleite/vim-agriculture'
```

## Usage

If you are already using [fzf.vim](https://github.com/junegunn/fzf.vim), you can use the provided `:AgRaw` / `:RgRaw` commands.
If you are already using [fzf.vim](https://github.com/junegunn/fzf.vim) or [fzf-lua](https://github.com/ibhagwan/fzf-lua) you can use the provided `:AgRaw` / `:RgRaw` commands.

```
```vim
:AgRaw func.*index
:AgRaw 'func.*index'
:AgRaw -Q 'function index()' app/Http/Controllers
Expand All @@ -55,7 +55,7 @@ If you are using another search wrapper, you'll need to wrap your input with `ag

If you are using one of the provided commands, you can hook into the provided `<Plug>` mappings in your `.vimrc`:

```
```vim
nmap <Leader>/ <Plug>AgRawSearch
vmap <Leader>/ <Plug>AgRawVisualSelection
nmap <Leader>* <Plug>AgRawWordUnderCursor
Expand All @@ -69,7 +69,7 @@ Likewise for `:RgRaw`, just substitute `AgRaw` in `RgRaw` in the above examples.

If you are using one of the provided commands, you can also set default command line options in your `.vimrc`:

```
```vim
let g:agriculture#ag_options = '--case-sensitive'
```

Expand All @@ -79,14 +79,35 @@ Again likewise for `:RgRaw` with `g:agriculture#rg_options`.

If you are using one of the provided commands, and want to disable smart quoting for CLI consistency:

```
```vim
let g:agriculture#disable_smart_quoting = 1
```

### Preview Window

Preview windows are now rendered by default in many [fzf.vim](https://github.com/junegunn/fzf.vim) commands. If you wish to customize or disable this behaviour, [see fzf.vim's documentation](https://github.com/junegunn/fzf.vim#preview-window) on preview windows.

[fzf-lua's](https://github.com/ibhagwan/fzf-lua) preview is been used as defined by default / setup for `grep` [see fzf.lua's documentation](https://github.com/ibhagwan/fzf-lua).

### Choosing wrapper

Currently

- [fzf.vim](https://github.com/junegunn/fzf.vim)
- [fzf-lua](https://github.com/ibhagwan/fzf-lua)

are supported and will be automatically chosen but can also be predefined with

```vim
let g:agriculture#fzf_wrapper = 'fzf.vim'
```

or

```vim
let g:agriculture#fzf_wrapper = 'fzf-lua'
```

## How It Works

Your input will be automatically quoted _unless_ the following conditions are met:
Expand Down
27 changes: 25 additions & 2 deletions autoload/agriculture.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function! agriculture#fzf_ag_raw(command_suffix, ...)
let userOptions = get(g:, 'agriculture#ag_options', '')
let command = 'ag --nogroup --column --color ' . s:trim(userOptions . ' ' . a:command_suffix)
let bang = a:000[0]
return call('fzf#vim#grep', extend([command, 1], [s:preview(bang), bang]))
return s:fzf_grep(command, bang)
endfunction

function! agriculture#fzf_rg_raw(command_suffix, ...)
Expand All @@ -32,7 +32,30 @@ function! agriculture#fzf_rg_raw(command_suffix, ...)
let userOptions = get(g:, 'agriculture#rg_options', '')
let command = 'rg --column --line-number --no-heading --color=always ' . s:trim(userOptions . ' ' . a:command_suffix)
let bang = a:000[0]
return call('fzf#vim#grep', extend([command, 1], [s:preview(bang), bang]))
return s:fzf_grep(command, bang)
endfunction

function! s:fzf_grep(command, bang)
let fzf_wrapper = get(g:, 'agriculture#fzf_wrapper', '')
if empty(fzf_wrapper)
if exists('g:loaded_fzf_lua')
let fzf_wrapper = 'fzf-lua'
endif
if empty(fzf_wrapper)
let fzf_wrapper = 'fzf.vim'
endif
let g:agriculture#fzf_wrapper = fzf_wrapper
endif

if fzf_wrapper == 'fzf-lua'
let opts = { 'raw_cmd' : a:command }
if a:bang
let opts['winopts'] = { 'fullscreen' : v:true }
endif
call v:lua.require'fzf-lua'.grep(opts)
else
return call('fzf#vim#grep', extend([a:command, 1], [s:preview(a:bang), a:bang]))
endif
endfunction

function! s:preview(bang, ...)
Expand Down