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

When opening a directory, insert mode is not activated #58

Open
mikavilpas opened this issue Apr 26, 2024 · 8 comments · Fixed by #66
Open

When opening a directory, insert mode is not activated #58

mikavilpas opened this issue Apr 26, 2024 · 8 comments · Fixed by #66
Labels
help wanted Extra attention is needed needs-reproduction

Comments

@mikavilpas
Copy link
Owner

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

@tkivela
Copy link

tkivela commented Apr 27, 2024

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.
So for me it requires manually entering normal mode (with esc) , switching to yazi floating window and then entering insert mode. Then it works.

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?).

@mikavilpas
Copy link
Owner Author

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 i.

@mikavilpas
Copy link
Owner Author

@tkivela hi, I just found a workaround/fix for this. Would you have time to verify it has been solved?
If there are issues remaining, I will reopen this issue.

@tkivela
Copy link

tkivela commented May 5, 2024

For some reason it still starts with insert mode in [No Name] buffer like this
image
If I manually enter normal mode (with Esc) and the switch to Yazi window it works ok.

@mikavilpas mikavilpas reopened this May 5, 2024
@mikavilpas
Copy link
Owner Author

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 repro.lua with the following contents:

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 nvim -u repro.lua. It will launch in a sandbox environment and install minimal packages for this session only.

In the sandbox neovim session, launch yazi and open a directory in it with enter. Does it stay in insert mode when the new directory is displayed for you?

@tkivela
Copy link

tkivela commented May 5, 2024

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 open_for_directories = truefor the plugin.

I can try the repro.lua script tomorrow if needed.

@mikavilpas
Copy link
Owner Author

Ok, that sounds like I still need to work on that part 🤔

@tkivela
Copy link

tkivela commented May 6, 2024

Good idea using repro config file!
When launching with nvim -u repro.lua and starting yazi.nvimwith the keymapping in the repro config (<leader>fy) the yazi window is in normal mode and stays in normal mode when entering directories. It works ok, no problems there. The parent window seems to be in TERMINALmode:
image

With nvim ./foodirectory -u repro.lua it now seems to open netrw instead of Yazi which is odd. With my own config it still opens Yazi window, but the focus in on wrong window and in insert mode. I have LazyVim "distro" as a base (https://www.lazyvim.org) so the difference might be in it. I tried to disable all my custom autocommands and even all set Vim options but it didn't make a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed needs-reproduction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants