nvim-tree.lua icon indicating copy to clipboard operation
nvim-tree.lua copied to clipboard

FindFile but not focus the tree

Open rockyzhang24 opened this issue 2 years ago • 6 comments

Is it possible to run NvimTreeFindFile but keep the focus on the file buffer, i..e, not focus on the tree automatically? Thank you so much.

rockyzhang24 avatar Apr 28 '22 19:04 rockyzhang24

~:NvimTreeFindFile | wincmd p ?~ doesn't seem to work :smile: there is no such functionnality in nvim-tree but i believe you can achieve this with a bit of scripting :)

function find_file_no_focus()
  require "nvim-tree".find_file()
  vim.cmd "wincmd p"
end

or something like that

kyazdani42 avatar Apr 28 '22 19:04 kyazdani42

Yes. This is exactly what I came up with. Do you think whether it will be better to add a boolean argument for find_file() like find_file(..., no_focus) as toggle() does to control "focus or not"? Thanks.

rockyzhang24 avatar Apr 28 '22 19:04 rockyzhang24

I know this does not exactly fit your requirement, however update_focused_file.enable will focus the tree on the file buffer without changing focus.

alex-courtis avatar Apr 30 '22 00:04 alex-courtis

@rockyzhang24 i think it could make sense yes :)

kyazdani42 avatar Apr 30 '22 09:04 kyazdani42

Is there any progress with this? Suggested options don't work I keep getting

Error detected while processing VimEnter Autocommands for "*":
Error executing Lua callback: ...fig/nvim/bundle/nvim-tree.lua/lua/nvim-tree/git/init.lua:99: table index is nil
stack traceback:
        ...fig/nvim/bundle/nvim-tree.lua/lua/nvim-tree/git/init.lua:99: in function 'load_project_status'
        ...vim/bundle/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:28: in function '_load'
        ...vim/bundle/nvim-tree.lua/lua/nvim-tree/explorer/init.lua:22: in function 'new'
        ....config/nvim/bundle/nvim-tree.lua/lua/nvim-tree/core.lua:15: in function 'init'
        .../.config/nvim/bundle/nvim-tree.lua/lua/nvim-tree/lib.lua:98: in function 'open'
        ...quad/.config/nvim/bundle/nvim-tree.lua/lua/nvim-tree.lua:94: in function 'open'
        ...quad/.config/nvim/bundle/nvim-tree.lua/lua/nvim-tree.lua:293: in function <...quad/.config/nvim/bundle/nvim-tree.lua/lua/nvim-tree.lua:292>
Press ENTER or type command to continue

But the future would help a lot.

naquad avatar Jun 21 '22 12:06 naquad

A proper solution with find_file(..., no_focus) would be best.

PRs gratefully accepted :)

alex-courtis avatar Jun 25 '22 02:06 alex-courtis

Tracked at #2011

alex-courtis avatar Mar 05 '23 05:03 alex-courtis