Open daUnknownCoder opened 3 months ago
I can't reproduce this. Please try with the original minimal config that was in the issue template. I could be due to other factors in your config and not necessarily due to telescope.
@jamestrew, so after a few updates, there's no magic mode, but sometimes it still opens any telescope
related stuff in insert mode...
Hi @jamestrew! I was facing this issue for a long time and didn't really know if it's a telescope bug or not.
I'm not sure if I'm talking about the issue that originally was described by @daUnknownCoder here, but you can look at it:
vim.api.nvim_create_autocmd('ModeChanged', {
pattern = '*:*',
callback = function() vim.print(vim.v.event.new_mode) end,
})
find_files
or live_grep
picker (can happen with other pickers as well, haven't checked that), you'll see i
letter in your console - meaning that you're in the insert mode, when in reality you're in normal.I'm the author of reactive.nvim
plugin that uses ModeChanged
autocmd to highlight anything and people opened issues on that error several times. For example here (the second part of the very first message).
I don't really know why ModeChanged
autocmd isn't triggered when your mode is actually changing from insert to normal when you select an entry in the pickers. Can it be a neovim issue instead?
I was playing with telescope sources and noticed this:
vim.schedule
, it does fix the issue for the find_files
picker, but not for live_grep
(what??)normal
command will fix the issue since it forcely changes the mode to normal. For example, if you put this line out of if-statement so that it's always executed, problem will be solved.My thoughts are that there can be something happening in the neovim event loop, that forgets to fire ModeChanged
autocmd when a lot of things are happening (buffer closing, opening another one, mode change, window focus change, cursor change etc), although I can be wrong on this one. The funny part is that if you put a delay in ModeChanged
, let's say for 1 sec, to check which mode you're in using vim.fn.mode(true)
, you'll see the normal mode there, although autocmd for its change wasn't triggered.
Please, let me know if I need to open a separate issue for this. I'm also ready to provide more information if that's needed!
And after you enter any buffer using find_files or live_grep picker (can happen with other pickers as well, haven't checked that), you'll see i letter in your console - meaning that you're in the insert mode, when in reality you're in normal.
I'm not experiencing this on either neovim 0.9.5 or master, telescope 0.1.6 or master.
Although semi-recently, there was a neovim issue that caused entering files from telescope to stay in insert mode. https://github.com/nvim-telescope/telescope.nvim/issues/2766 I'm pretty sure this is the cause of your issue @daUnknownCoder
This happened to me too, but disabling codeium.vim stopped it from happening.
This happened to me too, but disabling codeium.vim stopped it from happening.
you sure its due to codeium.vim
? i do use it so can you tell a workaround for that?
This happened to me too, but disabling codeium.vim stopped it from happening.
you sure its due to
codeium.vim
? i do use it so can you tell a workaround for that?
I don't know how to fix it, but I commented this line and it never happen again. https://github.com/Exafunction/codeium.vim/blob/31dd2962c81759be007895db6ce089feec397c86/autoload/codeium.vim#L504
function! codeium#RedrawStatusLine() abort
if s:using_codeium_status
" redrawstatus " comment this line
endif
endfunction
I've found that this happens only when the autocmd BufLeave
is triggered:
https://github.com/Exafunction/codeium.vim/blob/31dd2962c81759be007895db6ce089feec397c86/plugin/codeium.vim#L33
augroup codeium
autocmd!
autocmd InsertEnter,CursorMovedI,CompleteChanged * call codeium#DebouncedComplete()
autocmd BufEnter * if mode() =~# '^[iR]'|call codeium#DebouncedComplete()|endif
autocmd InsertLeave * call codeium#Clear()
" autocmd BufLeave * if mode() =~# '^[iR]'|call codeium#Clear()|endif " this autocmd is triggered
Again, this seems like the same issue from https://github.com/nvim-telescope/telescope.nvim/issues/2766 where the cause was doing certain operations inside a BufWinLeave
(similar to BufLeave
maybe). This was a neovim/vim issue that got fixed in nightly.
If you can try neovim 0.10 nightly if you're not already, this might be an easy way to see if the issue is fixed.
@jamestrew yes indeed, I tried tweaking everything and found out that it's not the bug you were describing. It's actually vim.cmd.normal
command. Sometimes, when it's called in insert mode, neovim doesn't trigger ModeChanged
command to reflect changes from insert mode to normal mode.
I don't really know if that's intentional, but from my understanding ModeChanged
should always be triggered no matter what (maybe except when eventignore
option is set).
so i guess i have to cross-post this on codeium.vim's github @Nebell
@Nebell, i am using getStatusString
for my lualine
{
'vim.fn["codeium#GetStatusString"]()',
fmt = function(str)
if str == " ON" then
return " "
elseif str == " OFF" then
return " "
elseif str == " * " then
return " "
else
return " " .. str
end
end,
},
so i guess i have to cross-post this on codeium.vim's github @Nebell
I don't know how to fix it on v0.9.5
, and I had tried, it's fixed on v0.10
nightly.
@rasulomaroff your issue appears to be a separate thing.
Can you create a new issue for it? I'm also curious if you are able to replicate your issue with my minimal config from above (https://github.com/nvim-telescope/telescope.nvim/issues/2995#issuecomment-2067869350)
It would be great if you can also try to replicate this without telescope and just using vim/neovim api as this may very well be not specific to telescope. You can see an example of how I did this for the issue affecting codeium.vim here https://github.com/neovim/neovim/issues/27038
@jamestrew It's really hard to reproduce this issue without using Telescope, because I believe it happens when several conditions are met.
Anyway, I don't think this is a telescope bug even though it happens only when I'm using it. As I stated above, when I put some vim.schedule
around vim.cmd.normal
calls in telescope sources it starts working.
So, to reproduce my issue you have to:
find_files
picker
-- restores the latest cursor position when opening a buffer
local group = vim.api.nvim_create_augroup('restore-cursor-position', {})
vim.api.nvim_create_autocmd('BufReadPre', { desc = 'Jump to the latest position in this buffer', group = group, callback = function(opts) vim.api.nvim_create_autocmd('FileType', { once = true, buffer = opts.buf, group = group, callback = function() local ft = vim.bo.filetype
-- ignore these filetypes
if ft == 'commit' or ft == 'rebase' then return end
local mark = vim.api.nvim_buf_get_mark(opts.buf, '"')
if mark[1] > 0 and mark[1] <= vim.api.nvim_buf_line_count(opts.buf) then
-- vim.api.nvim_win_set_cursor(0, mark)
vim.cmd.normal { 'g`"zz', bang = true }
end
end,
})
end,
})
vim.api.nvim_create_autocmd('ModeChanged', { pattern = ':', callback = function() vim.print(vim.v.event.new_mode) end, })
This autocmd basically restores the last position in a buffer
3. Just open the `find_files` picker and go to any file. In your console, you'll see `i` indicating that you're in the insert mode while in reality you're in normal. Basically, `ModeChanged` event wasn't triggered for the `i => n` transition.
What to note here:
1. Right above `vim.cmd.normal` call there's a `vim.api.nvim_win_set_cursor` api. If you use it instead, it'll work fine
2. If you put `vim.cmd.normal` into `vim.schedule`, it will also work fine (at least for `find_files` picker)
As I said, even though it happens using telescope, this is clearly not a telescope bug. Something when calling `vim.cmd.normal` while leaving a buffer or what? Really hard to say
Should I create a new issue for this? If so, clearly in `neovim` repo?
so the magic problem is solved i guess, but it really was a nuisance, i had to press Esc
a few times to go back to the real normal mode coz i was typing in normal mode, the keyword keys (d, y, h,j,k,l, o) worked like normal mode (dw, o, 5k) all of it was possible... It is solved ig in nightly
but in 0.9.5
it still exists, opening any file with any picker still goes into insert mode, somethings i've noticed so far:
codeium.vim
autocmd
Description
when i opened a file with
Telescope live_grep
orTelescope find_files
it opens the files, but they get opened in a differed custom mode i would say, like lualine shows it'sNormal
mode and my cursor is also thick [for insert it is thin], but i can type in like normal letters, if there's a keymap with that letter, the which-key pops up and i can go back to normal mode with<Esc>
but this is annoyingNeovim version
Operating system and version
6.7.9-arch1-1
Telescope version / branch / rev
v0.1.6 -> master
checkhealth telescope
Steps to reproduce
just try using the pickers...
Expected behavior
No magic mode, it automatically goes into sort of insert mode
Actual behavior
Kooha-2024-03-20-23-14-17.webm
i use lazy.nvim
Minimal config