vim-fern
vim-fern copied to clipboard
Close fern drawer after opening
I'm using nmap <silent> <Leader>f :Fern . -drawer -toggle<CR>
to open and close the fern drawer, I'd like it so when I select a file and press t
to tabedit, fern will automatically close the drawer before taking me to the new tab.
I tried this: https://github.com/lambdalisue/fern.vim/wiki/Tips#close-fern-after-open
But it did not work.
I'm sorry but I don't get your situation. How to reproduce the situation and what is actual and expected behavior?
@lambdalisue More details:
To reproduce:
- Open fern drawer with the mapping I specified in my original post from tab 1
- Select a file in the list, press
t
to tabedit the file (file opens in tab 2 and switches me to tab 2) - Upon going back to tab 1, the fern drawer is still open
The expected behavior is that after opening the file and going to the new tab (tab 2), the fern drawer would be closed automatically so that it is no longer open when I return to tab 1.
Hm.. It seems the feature request instead of bug. Current fern behavior is expected for me.
@evprkr seems need the new feature to close fern window after open files. For example defx.nvim has the feature like this.
" auto quit like behavior
nnoremap <silent><buffer><expr> <CR>
\ defx#do_action('multi', ['drop', 'quit'])
nnoremap <silent><buffer><expr> s
\ defx#do_action('multi', [['drop', 'split'], 'quit'])
@Shougo I didn't mean this to be a bug report, more of a "How do I do this?" or "Can this be added if it isn't already possible?" type of post.
I tried this: https://github.com/lambdalisue/fern.vim/wiki/Tips#close-fern-after-open
I think it does not work for tabedit
. Can you test it with other open commands?
I don't know it is bug or expected behavior.
I tried this: https://github.com/lambdalisue/fern.vim/wiki/Tips#close-fern-after-open
I think it does not work for
tabedit
. Can you test it with other open commands? I don't know it is bug or expected behavior.
I just put it back into my .vimrc
, closed vim. Reopened, opened the fern drawer, selected a file and pressed Enter
to open the file, and the fern drawer remained open. So it might be a bug, or maybe I am doing something wrong.
Hm. OK. I will try it.
I have tested below minimal vimrc and it does not work for action-open
but it does not work for action-tabopen
.
I think FernDo close -drawer -stay
does not support tab.
set rtp+=~/src/fern.vim
nnoremap <silent> <Space>f :Fern . -drawer -toggle<CR>
function! s:init_fern() abort
nnoremap <Plug>(fern-close-drawer) :<C-u>FernDo close -drawer -stay<CR>
nmap <buffer> <Plug>(fern-action-open-and-close)
\ <Plug>(fern-action-open)<Plug>(fern-close-drawer)
nmap <buffer> <Plug>(fern-action-tabopen-and-close)
\ <Plug>(fern-action-open:tabedit)<Plug>(fern-close-drawer)
nmap <buffer> <CR> <Plug>(fern-action-open-and-close)
nmap <buffer> t <Plug>(fern-action-tabopen-and-close)
nmap <buffer> q <Plug>(fern-close-drawer)
endfunction
augroup fern-custom
autocmd! *
autocmd FileType fern call s:init_fern()
augroup END
I just put it back into my .vimrc, closed vim. Reopened, opened the fern drawer, selected a file and pressed Enter to open the file, and the fern drawer remained open. So it might be a bug, or maybe I am doing something wrong.
You need to map <CR>
like my config.
Note: I think the documentation should be updated though...
As @Shougo mentioned, FernDo
is for executing a command on a current tab page.
Unfortunately, there is no simple solution for your case. You need to write a lot of Vim script to do that (e.g. save win_getid()
before and call win_execute(winid, 'close')
or whatever after t
)
Implementation that works for me:
vim.api.nvim_buf_set_keymap(0, "n", "t", "<Plug>(fern-action-open:tabedit) gt :FernDo close -drawer<CR> gT")