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

Better handling of <esc> #126

Closed
GordianDziwis opened this issue Jun 23, 2024 · 13 comments
Closed

Better handling of <esc> #126

GordianDziwis opened this issue Jun 23, 2024 · 13 comments
Labels
enhancement New feature or request

Comments

@GordianDziwis
Copy link
Contributor

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:

vim.api.nvim_create_autocmd('ModeChanged', {
buffer = yazi_buffer,
callback = function()
-- 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.
vim.cmd('startinsert')
end,
})

@mikavilpas
Copy link
Owner

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?
#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
Copy link
Contributor Author

#127 works fine!

@mikavilpas
Copy link
Owner

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

-- 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
        '<leader>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
Copy link
Contributor Author

You have set open_for_directories = false...

@mikavilpas
Copy link
Owner

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

@mikavilpas
Copy link
Owner

Something seems to conflict in lazyvim:

esc.mov
Details

-- 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
        '<leader>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
Copy link
Contributor Author

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
Copy link
Owner

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

@GordianDziwis
Copy link
Contributor Author

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
Copy link
Owner

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
Copy link
Contributor Author

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 added a commit that referenced this issue Jun 29, 2024
@mikavilpas
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants