junegunn / fzf.vim

fzf :heart: vim
MIT License
9.65k stars 584 forks source link

Preview window empty #362

Open nayed opened 7 years ago

nayed commented 7 years ago

Hi, first of all thanks for your vim plugins, I can't think of using (neo)vim without it!

So my issue is that preview window doesn't seem to work for me. Even with the basic config + the readme "advanced customization" part:

set nocompatible hidden laststatus=2

if !filereadable('/tmp/plug.vim')
  silent !curl --insecure -fLo /tmp/plug.vim
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

source /tmp/plug.vim
call plug#begin('/tmp/plugged')
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
call plug#end()

command! -bang -nargs=* GGrep
  \ call fzf#vim#grep('git grep --line-number '.shellescape(<q-args>), 0, <bang>0)

command! -bang Colors
  \ call fzf#vim#colors({'left': '15%', 'options': '--reverse --margin 30%,0'}, <bang>0)

command! -bang -nargs=* Ag
  \ call fzf#vim#ag(<q-args>,
  \                 <bang>0 ? fzf#vim#with_preview('up:60%')
  \                         : fzf#vim#with_preview('right:50%:hidden', '?'),
  \                 <bang>0)

command! -bang -nargs=* Rg
  \ call fzf#vim#grep(
  \   'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1,
  \   <bang>0 ? fzf#vim#with_preview('up:60%')
  \           : fzf#vim#with_preview('right:50%:hidden', '?'),
  \   <bang>0)

command! -bang -nargs=? -complete=dir Files
  \ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)

Do I need to add some (linux?) package on my machine to enable it? (Already have coderay)

peek 30-04-2017 00-38

nayed commented 7 years ago

Ok I tried this:

set nocompatible hidden laststatus=2

if !filereadable('/tmp/plug.vim')
  silent !curl --insecure -fLo /tmp/plug.vim
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

source /tmp/plug.vim
call plug#begin('/tmp/plugged')
Plug 'junegunn/fzf', { 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
call plug#end()

let g:fzf_files_options =
   \ '--preview "(coderay {} || cat {}) 2> /dev/null | head -'.&lines.'"'

Now it works for Files. Can I do the same for Ag? peek 30-04-2017 02-37

junegunn commented 7 years ago
command! -bang -nargs=? -complete=dir Files
  \ call fzf#vim#files(<q-args>, fzf#vim#with_preview(), <bang>0)

command! -bang -nargs=* Ag
  \ call fzf#vim#ag(<q-args>,
  \                 <bang>0 ? fzf#vim#with_preview('up:60%')
  \                         : fzf#vim#with_preview('right:50%:hidden', '?'),
  \                 <bang>0)

Both snippets are fine and should work as expected. g:fzf_files_options should not be needed.

Check if bin/preview.rb or bin/preview.sh works:

bin/preview.rb /tmp/plug.vim:100
bin/preview.sh /tmp/plug.vim:100
nayed commented 7 years ago

peek 30-04-2017 18-49 I suppose the preview.rb should've done the same thing? I have ruby 2.4.0

junegunn commented 7 years ago

The ruby version also applies syntax highlighting if you have any of highlight, coderay, or rougify, and I have confirmed that the script works with both Ruby 2.0 and 2.4. Check if you have any of the mentioned tools and if so, if they work as expected.

https://github.com/junegunn/fzf.vim/blob/d99169da2d9b910839ad826d3d501c87b5ba9bb9/bin/preview.rb#L7

nayed commented 7 years ago

Already had coderay and rougify on my computer, I installed highlight and it's working. Yay! But it seems weird to me so I made a little test: I removed highlight of my computer and it's not working... I deleted highlight -O ansi -l {} of the COMMAND array and it's working :neutral_face:

Anyway everything is OK for me, thank you for your time :+1:

junegunn commented 7 years ago

Any idea why highlight is not working? Which version do you have?

nayed commented 7 years ago

Well, on another machine with Linux Mint 17 I have, I'm 100% sure that I did not installed highlight there and still I have a package called highlight. Apparently it's not the same package. https://bugs.launchpad.net/linuxmint/+bug/815005

So what I think happened is that the first time I had my issue, in the COMMAND array in preview.rb it found a highlight on my system and it thought it was the good package to call, which is not.

So I replace the COMMAND array with COMMAND = %[(coderay {} || rougify {} || highlight -O ansi -l {} || cat {}) 2> /dev/null] and it works