Closed mikatpt closed 2 years ago
I have the same issue
I have the same issue. I put the drawer on the right by default and the cursor is put back on the rightmost split.
I have the same issue. Here is a dirty workaround, until the issue is resolved:
" START: Workaround for buggy NvimTreeToggle
let g:nt_workaround_stack = []
function! NvimTreeToggleWorkaround()
let l:ft = &filetype
let l:last = g:nt_workaround_stack[len(g:nt_workaround_stack)-2]
if l:ft ==# "NvimTree"
NvimTreeClose
let g:nt_workaround_stack = []
call win_gotoid(l:last)
else
NvimTreeToggle
endif
endfunction
function! NvimTreeToggleAdd()
if len(g:nt_workaround_stack) > 10
call remove(g:nt_workaround_stack, 0, -2)
endif
call add(g:nt_workaround_stack, win_getid())
endfunction
augroup my_nvimtreegroup
autocmd!
au WinEnter * call NvimTreeToggleAdd()
augroup END
nnoremap <C-n> :<c-u>call NvimTreeToggleWorkaround()<cr>
" END: Workaround for buggy NvimTreeToogle
@Remich While you have implemented one, I have a shorter version without au
:
local NOREF_NOERR_TRUNC = { noremap = true, silent = true, nowait = true }
vim.api.nvim_set_keymap('n', ';', '<cmd>lua toggle_nvim_tree_open()<CR>', NOREF_NOERR_TRUNC)
function _G.toggle_nvim_tree_open()
-- Check nvim-tree is open: https://github.com/kyazdani42/nvim-tree.lua/blob/65b8b19c8bcea36e37474338c7e2d2fea95553d3/lua/nvim-tree.lua#L22
if (not require'nvim-tree.view'.win_open() or vim.bo.filetype ~= 'NvimTree') then
vim.cmd('NvimTreeFindFileToggle')
else
vim.cmd('NvimTreeFindFileToggle')
vim.cmd('wincmd p')
end
end
Explanation:
;
to your favorite shortcut.if ...
:
NvimTreeFindFileToggle
.else
:
wincmd p
, which moves the cursor to the previous buffer, to fix this issue after we call NvimTreeFindFileToggle
.
Steps to reproduce:
NvimTreeToggle
twicePreviously, using
NvimTreeToggle
had memory of which split I was currently in - please let me know if there's a way to restore the previous behavior? Thanks so much!