-
Notifications
You must be signed in to change notification settings - Fork 28
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
When opening a directory, insert mode is not activated #58
Comments
Tested this a bit this morning and for me it enters the insert mode, but the active window is not the yazi floating window but the window with empty buffer underneath it. I've not done much Lua/Neovim code but I think if something like this would be run after opening directory it might help: -- Check if the current buffer's filetype is 'yazi'
local current_ft = vim.bo.filetype
if current_ft ~= 'yazi' then
-- Iterate through available windows
for _, win in ipairs(vim.api.nvim_list_wins()) do
local buf = vim.api.nvim_win_get_buf(win)
-- Check if the buffer's filetype is 'yazi'
local win_ft = vim.api.nvim_buf_get_option(buf, 'filetype')
if win_ft == 'yazi' then
-- Switch to the window and enter insert mode
vim.api.nvim_set_current_win(win)
vim.cmd('startinsert')
break
end
end
end I tried to insert the code and test it with the plugin but haven't found the right place to insert it to (maybe some kind of lifecycle issue with autogroups?). |
I spent a couple of hours trying to crack this, but couldn't solve it yet. Let's keep this open. A solution may be available later. For now I think the best thing you can do is manually enter insert mode after opening a directory with |
@tkivela hi, I just found a workaround/fix for this. Would you have time to verify it has been solved? |
Hmm that's super strange. I noticed for me it now works after neovim has already started. But opening a directory from the command line does not work now. Can you try the following? Create a file called Details
-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify('./.repro', ':p')
-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'cache' }) do
vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end
-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
'git',
'clone',
'--filter=blob:none',
'https://github.com/folke/lazy.nvim.git',
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
vim.g.mapleader = ' '
-- install plugins
local plugins = {
'folke/tokyonight.nvim',
{
'mikavilpas/yazi.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
},
event = 'VeryLazy',
keys = {
{
-- 👇 choose your own keymapping
'<leader>fy',
function()
require('yazi').yazi()
end,
{ desc = 'Open the file manager' },
},
},
setup = function(_, opts)
require('yazi').setup(opts)
end,
---@type YaziConfig
opts = {
open_for_directories = true,
},
},
}
require('lazy').setup(plugins, {
root = root .. '/plugins',
})
vim.cmd.colorscheme('tokyonight') Next, start neovim with In the sandbox neovim session, launch yazi and open a directory in it with |
Yes the problem that I gave a screenshot is in the case neovim is opened from the terminal with a directory as a parameter and config option I can try the repro.lua script tomorrow if needed. |
Ok, that sounds like I still need to work on that part 🤔 |
Good idea using repro config file! With |
in the file lua/yazi.lua, I put this piece of code inside of the vim.schedule function and it fixed this problem for me. |
Hmm that seems like this might be some kind of tricky timing issue. @dinomon456 would you have any idea if this could be reproduced? Can you try if you can reproduce it using the reproduction script here https://github.com/mikavilpas/yazi.nvim/blob/master/repro.lua |
when i use the reproduction script with options |
Awesome, thanks! I am able to reproduce this now. I'll try to fix it. |
Yazi.nvim has a feature where you can specify `open_for_directories = true` to automatically open yazi when opening a directory in Neovim. In some cases, opening a directory when starting Neovim from the command line would show yazi, but the window under yazi was selected. Yazi was supposed to have been focused instead. This was due to the default netrw file manager not having a file name for the buffer that was opened. I don't know why this only happened in some cases. Fixes #58
update readme
When you open yazi and then highlight (hover) a directory item, and press enter to open it, a new floating window with yazi is opened.
However, this new floating window does not currently seem to start in insert mode, which means keybindings don't work.
You can currently work around this limitation by pressing
i
to enter insert mode, but a better solution should be come up with.This was very briefly discussed in #55
The text was updated successfully, but these errors were encountered: