lambdalisue / vim-fern

🌿 General purpose asynchronous tree viewer written in Pure Vim script
MIT License
1.29k stars 49 forks source link

How to preview file contents by j/k like VS code's preview mode #193

Closed bangedorrunt closed 4 years ago

bangedorrunt commented 4 years ago

it would be helpful if we could see the content of file while traveling through fern tree

lambdalisue commented 4 years ago

What do you mean by "preview"? You can open it.

bangedorrunt commented 4 years ago

i mean when i travel through the tree up and down, a temporary preview buffer would show up without opening the file. this will work just like fzf preview.

lambdalisue commented 4 years ago

What is a temporary preview buffer? Vim itself has preview window. Are you talking about that? Or are you talking about the floating window in Neovim and popup in Vim8?

Anyway, I cannot imagine what you are exactly talking about. Please explain the feature with some screenshots and more detailed definitions (what is the preview window, where it should be placed, or whatever) for both styles (project drawer style, split window style)

bangedorrunt commented 4 years ago

sorry for any confusion. if you use vscode you might come across this behaviour aka preview mode

lambdalisue commented 4 years ago

I'm sorry but that link doesn't help me... I could not get any actual image or behavior or whatever from a screenshot pasted on that link (a part of the screenshot of VS code?)

image

bangedorrunt commented 4 years ago

with preview mode

Screen Recording 2020-09-06 at 12 58 41 pm

without preview mode

Screen Recording 2020-09-06 at 1 00 54 pm

pls look at the tab, new file will not open a new tab in preview mode unless you edit this file.

in (neo)vim, preview mode will reuse current buffer without creating a new buffer when we use j, k to navigate up and down. it would work like fzf.vim with --preview option

i'm not sure if it's possible to do so.

lambdalisue commented 4 years ago

Now I got it. Well, I'm not sure if it's useful as VS code while it would cause some performance issue but combinations of fern#smart#leaf(), fern#smart#drawer() and <C-w>p would mimic that behavior like

Kapture 2020-09-06 at 12 53 06

The entier code is something like:

function! s:fern_preview_init() abort
  nmap <buffer><expr>
        \ <Plug>(fern-my-preview-or-nop)
        \ fern#smart#leaf(
        \   "\<Plug>(fern-action-open:edit)\<C-w>p",
        \   "",
        \ )
  nmap <buffer><expr> j
        \ fern#smart#drawer(
        \   "j\<Plug>(fern-my-preview-or-nop)",
        \   "j",
        \ )
  nmap <buffer><expr> k
        \ fern#smart#drawer(
        \   "k\<Plug>(fern-my-preview-or-nop)",
        \   "k",
        \ )
endfunction

augroup my-fern-preview
  autocmd! *
  autocmd FileType fern call s:fern_preview_init()
augroup END

" You need this otherwise you cannot switch modified buffer
set hidden
bangedorrunt commented 4 years ago

awesome! that's exactly what i want. imho, you could make it as an option for the plugin let g:fern#previewmode=0 etc.

thank you so much!

lambdalisue commented 4 years ago

imho, you could make it as an option for the plugin let g:fern#previewmode=0 etc.

I'm sorry but I'm trying to avoid adding features as much as possible to keep the fern.vim itself simple and clean. Instead of adding the feature, I've added Wiki section for that https://github.com/lambdalisue/fern.vim/wiki/Tips#preview-leaf-content-by-jk-like-vs-code