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

Only map keys when the preview window is open #19

Open
arashm opened this issue Oct 26, 2021 · 1 comment
Open

Only map keys when the preview window is open #19

arashm opened this issue Oct 26, 2021 · 1 comment

Comments

@arashm
Copy link

arashm commented Oct 26, 2021

Thanks for the great set of Plugins. I have this piece of config as suggested in the readme:

function! s:fern_settings() abort
  ....
  nmap <silent> <buffer> <C-d> <Plug>(fern-action-preview:scroll:down:half)
  nmap <silent> <buffer> <C-u> <Plug>(fern-action-preview:scroll:up:half)
endfunction

I use <C-d> and <C-u> in the fern itself to jump up and down the list of directories/files as well, but setting it here causes the fern/vim to throw an error:

Error detected while processing function fern_preview#half_down[2]..<SNR>187_info:
line    3:
E716: Key not present in Dictionary: "width,   'height': l:info.height,   'topline': l:info.firstline }"

Is there a way to only map those keys when a preview window is open, and do the regular <C-d>, <C-u> when there's no preview window?

@knupska
Copy link

knupska commented Mar 9, 2022

I also wanted this behaviour and was able to cobble this together:

if !exists("b:fern_is_preview")
  let b:fern_is_preview = 0
endif
function! FernPreviewToggle()
  if b:fern_is_preview
    :execute "normal \<Plug>(fern-action-preview:close)"
    :execute "normal \<Plug>(fern-action-preview:auto:disable)"
    nunmap <buffer> <C-d>
    nunmap <buffer> <C-u>
    let b:fern_is_preview = 0
  else
    :execute "normal \<Plug>(fern-action-preview:open)"
    :execute "normal \<Plug>(fern-action-preview:auto:enable)<Plug>(fern-action-preview:open)"
    nmap <silent> <buffer> <C-d> <Plug>(fern-action-preview:scroll:down:half)
    nmap <silent> <buffer> <C-u> <Plug>(fern-action-preview:scroll:up:half)
    let b:fern_is_preview = 1
  endif
endfunction

nmap <silent> <buffer> p :call FernPreviewToggle()<CR>

It should be placed within the init_fern() function as outlined here, so that it acts upon the buffer that fern is in.

It will only work so long as the preview is open/closed via the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants