fzf#vim#grep() vs. FZF_PREVIEW_COMMAND
- Dominant language
- Vim Script
- Stars
- 10.3k
- Forks
- 608
- Avg merge
- 5d 8h
- Merged PRs (30d)
- 2
Description
- Category
- [x] Question
- Vim
- [x] Vim
First, I have the following script named `fzfcodepreview`:
#!/bin/bash
IFS=':' read -r -a INPUT <<< "$1"
file=${INPUT[0]}
line=${INPUT[1]}
if hash bat 2>/dev/null
then
if ! [ -z $line ]
then
topline=$(($line - 5))
if [ $topline -lt 1 ]
then
topline=1
fi
bat --style=numbers --color=always --theme=silence --line-range $topline: --highlight-line $line "$file"
else
bat --style=numbers --color=always --theme=silence "$file"
fi
else
cat "$file"
fi
And if I run something like:
rg --line-number --no-heading if | fzf --preview='fzfcodepreview {}'
...`bat` specifically highlights the line with the match (thanks to passing matches to my preview script **including line numbers**, like `file.txt:5`).
Now, I also have shell variable `FZF_PREVIEW_COMMAND` set to `'fzfcodepreview {}'`.
However, if I define `:Rg` command in my `$VIMRC` like the following:
command! -bang -nargs=* -complete=file Rg
\ call fzf#vim#grep('rg --column --line-number --no-heading --smart-case --hidden --follow --color=always ' .
\ , 1, fzf#vim#with_preview(), 0)
...it does pass it correctly to my preview script but **fails to tell the script the line's number.**
But if I define `:Rg` via `fzf#wrap()`, like this:
command! -bang -nargs=* -complete=file Rg call fzf#run(fzf#wrap({
\ 'source': 'rg --column --line-number --no-heading --smart-case --hidden --follow --color=never ' . ,
\ 'down': '40%',
\ 'options': ['--preview', 'fzfcodepreview {}']}))
...the line with the match gets highlighted again :)
Now, my question is the following: is it possible to use `fzf#vim#grep()` AND get the matched line's number for the preview script?
Thank you :)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.