lualine.nvim
lualine.nvim copied to clipboard
Bug: flicker when running keymap
Self Checks
- [x] I'm using the latest lualine.
- [x] I didn't find the issue in exsisting issues or prs.
How to reproduce the problem
Map a key to a command. Good example can be seen when using delimitmate
plugin where there are imaps for <space>
and <bs>
. You can also add your own maps, such as map m :echo "hello"<cr>
, but for the very simple keymaps the flicker doesn't happen every time, only sometimes. But if you try running this keymap repeatedly in quick succession you should see the flicker even with this simple map.
Expected behaviour
No flicker of lualine should occur when you run the keymap.
Actual behaviour
Lualine flickers. Mode seems to switch for a split second to command and this redraws the lualine.
Aditional information
This bug is most apparent when other plugins are involved (such as delimitmate). However, this is clearly an issue with lualine, not other plugins. Of course those keymaps do cause vim to switch to command mode and back, but I think lualine should be able to filter out these super short switches caused by keymaps.
Initially I thought this was a different issue, but on second look it seems that this is identical to the issue #852. Nevertheless, I won't close this just yet since I think the additional context I described might be helpful: I am pretty sure the flickering described in #852 is actually not happening simply because new line is added but because the user have a map for
You should use :h <cmd>
for your mappings instead. <cmd>
exists for this exact reason.
It happens when running <Plug>
keymaps as well, e.g.:
vim.keymap.set('', 'w', '<Plug>CamelCaseMotion_w', opt_plug)
vim.keymap.set('', 'b', '<Plug>CamelCaseMotion_b', opt_plug)
vim.keymap.set('', 'e', '<Plug>CamelCaseMotion_e', opt_plug)
I don't think this case can be solved by adding <Cmd>
. It can maybe be fixed in the CamelCaseMotion plugin, but the problem does not happen in other statusline plugins like lightline
.
I noticed this with andymass/vim-matchup. I disabled the default mappings for that plugin and made the mappings myself using <cmd>
(instead of :<c-u>
like vim-matchup does) as suggested by @folke. The flickering between Insert and Command mode stopped, but the statusline still flickers. So better, but not gone.
I noticed that this behavior does not occur in commit 1e53bf7386619722b7cfae0d541b45978f0152e4, and due to the cursor movement done by vim-matchup, I think the flickering might be due to adding CursorMoved
in 664c688974a7f183f6d6edae70c6aa117dcbd009. Whether that's the root cause (versus a bug elsewhere that this is a symptom of), I'm not sure.
To add to this report, I've been having the same issue with lualine flickering to command mode from insert when executing <C-R>=
maps. For instance, the LunarWatcher/auto-pairs plugin makes the following maps:
inoremap <buffer> <silent> <BS> <C-R>=autopairs#AutoPairsDelete()<CR>
inoremap <buffer> <silent> <SPACE> <C-]><C-R>=autopairs#AutoPairsSpace()<CR>
This leads to lualine's status line flickering every time space or backspace are typed in insert mode.
Edit to confirm that https://github.com/nvim-lualine/lualine.nvim/commit/b87e47e1dee3cf96fc787f24e282ed5b52ed2fd2 is the cause of this; basically the same issue @dabbertorres points out, only CursorMovedI was later added to this variable causing the issue in insert mode also. Can this be reverted?