folke / flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Apache License 2.0
2.47k stars 33 forks source link

bug: `<esc>` key not working due to remap #302

Closed JeanMertz closed 9 months ago

JeanMertz commented 9 months ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0-dev-80f75d0

Operating system/version

macOS 14.1

Describe the bug

Using <Esc> to disable Flash doesn't work for me, probably because I remapped my key as such:

<Cmd>lua MiniMap.refresh({}, {lines = false, scrollbar = false})<Cr><Cmd>nohlsearch<Cr>

Steps To Reproduce

n/a

Expected Behavior

<Esc> should move out of "Flash mode".

Repro

No response

JeanMertz commented 9 months ago

To clarify; <Esc> works as expected in search mode (e.g. / or ?), but not in char mode (f, F, etc.).

JeanMertz commented 9 months ago

I resolved it by adding the following to my custom keymap:

<Cmd>lua require('flash.plugins.char').state:hide()<Cr>

Not sure if this is the right approach (it appears so, looking at the code), but it works. Posting it here for anyone else running into this.

phanen commented 9 months ago

Same problem, but I found the root cause is that my <esc> was mapped previously.

Work it out by appending this to my previous noremap:

vim.api.nvim_feedkeys(vim.keycode "<esc>", "n", false)
cameronr commented 3 weeks ago

For anyone finding this in google, LavyVim has a clever solution where it includes the escape key in the mapping, which gives flash (and any other plugin that might care) a chance to see the escape key

-- Clear search with <esc>
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", { desc = "Escape and Clear hlsearch" })