mikavilpas / yazi.nvim

A Neovim Plugin for the yazi terminal file manager
MIT License
214 stars 7 forks source link

Better handling of `<esc>` #126

Closed GordianDziwis closed 5 days ago

GordianDziwis commented 1 week ago

Neovim captures the first <esc> when in a yazi buffer.

As a fix I added vim.keymap.set('t', '<esc>', '<esc>', { buffer = yazi_buffer }) in the set_keymappings_function.

Then this hack is not needed anymore: https://github.com/mikavilpas/yazi.nvim/blob/1efb48847944c4036bfd4114590bd617b274adf9/lua/yazi/window.lua#L93-L100

mikavilpas commented 1 week ago

Hmm, interesting idea. This is definitely hacky and could be improved.

However, I tried this out a bit and ran into some issues. Can you see if it works for you on this branch better-handling-of-esc-idea? https://github.com/mikavilpas/yazi.nvim/pull/127

I added instructions on how this could be tried out to https://github.com/mikavilpas/yazi.nvim/blob/master/documentation/for-developers/setting-up.md#managing-your-development-code

GordianDziwis commented 1 week ago

127 works fine!

mikavilpas commented 1 week ago

For me, running nvim -u repro.lua . (to start neovim with yazi.nvim showing the current directory) doesn't show yazi.nvim after this change. The suggested change might have caused this, and this should be fixed before merging the change in.

Details

```lua -- You can use this file to reproduce an issue with your configuration. ---@module "yazi" ---@module "lazy" -- 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 the following plugins ---@type LazySpec local plugins = { 'folke/tokyonight.nvim', { 'mikavilpas/yazi.nvim', branch = 'better-handling-of-esc-idea', dependencies = { 'nvim-lua/plenary.nvim', }, event = 'VeryLazy', keys = { { -- 👇 choose your own keymapping 'fy', function() require('yazi').yazi() end, { desc = 'Open the file manager' }, }, }, ---@type YaziConfig opts = { open_for_directories = false, }, }, } require('lazy').setup(plugins, { root = root .. '/plugins', }) vim.cmd.colorscheme('tokyonight') -- add anything else here ```

GordianDziwis commented 5 days ago

You have set open_for_directories = false...

mikavilpas commented 5 days ago

Oops, you're right. My bad. I'll look into it more.

mikavilpas commented 5 days ago

Something seems to conflict in lazyvim:

https://github.com/mikavilpas/yazi.nvim/assets/300791/a50d0da7-d497-4fbe-a455-0e6c905add6e

Details

```lua -- You can use this file to reproduce an issue with your configuration. ---@module "yazi" ---@module "lazy" -- 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 the following plugins ---@type LazySpec local plugins = { 'folke/tokyonight.nvim', { 'LazyVim/LazyVim', import = 'lazyvim.plugins' }, { 'mikavilpas/yazi.nvim', dependencies = { 'nvim-lua/plenary.nvim', }, branch = 'better-handling-of-esc-idea', event = 'VeryLazy', keys = { { -- 👇 choose your own keymapping 'fy', function() require('yazi').yazi() end, { desc = 'Open the file manager' }, }, }, ---@type YaziConfig opts = { open_for_directories = true, }, }, { 'nvim-neo-tree/neo-tree.nvim', opts = { filesystem = { hijack_netrw_behavior = 'disabled', }, }, }, } require('lazy').setup(plugins, { root = root .. '/plugins', }) vim.cmd.colorscheme('tokyonight') -- add anything else here ```

I like this idea a lot though. If you can resolve this issue, I would like to merge it.

GordianDziwis commented 5 days ago

The issue is: On pressing <esc> your yazi window leaves the insert mode?

I do not have this issue with your config, but in the video your status line is modified, while mine is vanilla, so I would guess there is a conflict with a plugin.

mikavilpas commented 5 days ago

That's it exactly. Can you reproduce the behaviour with the reproduction script in my previous message?

GordianDziwis commented 5 days ago

Nope, works also fine with the updated repro script.

Maybe you are running in this issue again:

     -- HACK Sometimes pressing "<esc><esc>" exits insert mode the first time it's pressed.
      -- Work around this by starting insert mode after the first time the mode changes.

Maybe try deleting the .repro directory

mikavilpas commented 5 days ago

Just tried deleting the .repro directory, but I'm still getting the same behaviour. Did you also try after removing your .repro directory?

I think it should effectively start over from scratch in that case.

GordianDziwis commented 5 days ago

LazyVim has in the Terminal mode a mapping for <esc> defined:

t  <Esc><Esc>  * <C-\><C-N>
                 Enter Normal Mode
    Last set from ~/.repro/plugins/LazyVim/lua/lazyvim/util/init.lua line 218
mikavilpas commented 5 days ago

Ooh I see, nice find! I was able to shadow that binding for yazi.nvim only, so that issue goes away as far as I can tell.

Would you have time to review #127? Let me know if you would prefer not being included as the co-author.

mikavilpas commented 5 days ago

Just merged the refactor in. Thanks again for the idea and help!