nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.59k stars 827 forks source link

selected file opens in insert mode directly #2027

Closed abdellatif-temsamani closed 2 years ago

abdellatif-temsamani commented 2 years ago

Description

i selected the file that i want, the selected file opens in insert mode directly

Neovim version

NVIM v0.8.0-dev+503-g274609a109
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

arch linux

checkhealth telescope

telescope: require("telescope.health").check()
========================================================================
## Checking for required plugins
  - OK: plenary installed.
  - OK: nvim-treesitter installed.

## Checking external dependencies
  - OK: rg: found ripgrep 13.0.0
  - OK: fd: found fd 8.4.0

## ===== Installed extensions =====

Steps to reproduce

  1. nvim
  2. :Telescope find_files
  3. select a file

Expected behavior

Actual behavior

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
    require('packer').startup {
        {
            'wbthomason/packer.nvim',
            {
                'nvim-telescope/telescope.nvim',
                requires = {
                    'nvim-lua/plenary.nvim',
                    { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
                },
            },
            -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
        },
        config = {
            package_root = package_root,
            compile_path = install_path .. '/plugin/packer_compiled.lua',
            display = { non_interactive = true },
        },
    }
end

_G.load_config = function()
    local actions = require("telescope.actions")

    require("telescope").setup({
        defaults = {
            prompt_prefix = " ",
            color_devicons = true,
            selection_strategy = "closest",

            file_previewer = require("telescope.previewers").vim_buffer_cat.new,
            grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new,
            qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new,

            mappings = {
                i = {
                    ["<C-x>"] = false,
                    ["<C-q>"] = actions.send_to_qflist,
                    ["<C-h>"] = "which_key",
                },
            },
        },

        extensions = {

            fzf = {
                fuzzy = true, -- false will only do exact matching
                override_generic_sorter = true, -- override the generic sorter
                override_file_sorter = true, -- override the file sorter
                case_mode = "smart_case", -- or "ignore_case" or "respect_case"
                -- the default case_mode is "smart_case"
            },
            project = {
                base_dirs = {
                    "~/programming",
                },
                hidden_files = false,
            },
        },
    })

    require('telescope').load_extension('fzf')
    -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
    print("Installing Telescope and dependencies.")
    vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
GaetanLepage commented 2 years ago

I encounter the same problem currently

fedreg-bn commented 2 years ago

Seeing the same on

abdellatif-temsamani commented 2 years ago

I encounter the same problem currently

i think if downgrade to NVIM v0.7.2 it should be fixed

fedreg-bn commented 2 years ago

@abdellatif-temsamani I'm running v 0.7.0 and had it, but seems like just deleting Telescrope and reinstalling it has fixed it for me 🤷

if the issue pops back up I'll debug a bit more but unable to reproduce at the moment

abdellatif-temsamani commented 2 years ago

@fedreg-bn i just reinstalled and it seems to be be working, thanks

Conni2461 commented 2 years ago

Weird we haven't changed anything. Hopefully no one else runs into this issue again :grimacing:

fedreg-bn commented 2 years ago

@Conni2461 this issue popped back up for me again this morning. It happened right after I updated Telescope.

As you said, no changes in recent commits that would cause anything like this from what I could see.. could it be something not getting fully updated??

nvim 0.7.0 using vim-plug Still using full vimscript init only Telescope related configs are a few keybindings to call a few Telescope functions... nothing fancy.

Takes 2 seconds to reinstall so no big deal at all but just sharing in case anyone else mentions and it's helpful.

If you want any specific info, I can look if/when it happens again. Unfortunately it was at an inopportune time this morning so couldn't look into it at all.

Thanks for the great work on Telescope!!

PopBogdan97 commented 1 year ago

The same problem just popped up for me after I updated the plugins. I tried to reinstall Telescope, but it did not work for me. Actually, the exact behavior is that it opens the file in the same mode telescope is in when you open the selected file.

It may be related also to this issue? #1882

Any other hints on what it could be?

theoribeiro commented 1 year ago

Exact same issue happening with me @PopBogdan97 . Can confirm that Telescope maintains the mode it is currently on when you open the buffer.

Have you found a workaround for it?

PopBogdan97 commented 1 year ago

@theoribeiro Unfortunately I did not found any workaround for it at that moment, it just started to behave correctly after a while. I don't know yet why it was not working nor why it is working now...

theoribeiro commented 1 year ago

Thanks for the update. No idea what's causing it either, I'll try reinstalling but it's pretty annoying to be honest, lol. It breaks my flow as I end up always editing the file by mistake after I open it.

zjykzk commented 1 year ago

same problem

yannick1974 commented 1 year ago

I have the same problem using neovim compiled from master and opening files with the file or the history (old_files) pickers.

Following https://www.reddit.com/r/neovim/comments/12j9jlp/neovim_sometimes_turned_into_insert_mode_when_it/ and reverting https://github.com/neovim/neovim/pull/22984 makes telescope work as expected. Note that the patch went to the release-0.9 branch and will end up in version 0.9.1 I suppose.

https://github.com/neovim/neovim/issues/22924 may also be interesting.

ttytm commented 1 year ago

Yep that's a bit mind mind boggling. It's hard to track to what is actually causing it.

Also, calling "stopinsert" doesn't seem to work, even when scheduling it. So not an optimal but at least consistent quickfix Im using for now which works with the latest nvim version is:

nx.au({ -- Prevent entering buffers in insert mode.
    "WinLeave",
    callback = function()
        if vim.bo.ft == "TelescopePrompt" and vim.fn.mode() == "i" then
            vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "i", false)
        end
    end,
})
medwatt commented 1 year ago

Has there been a fix for this issue?

jamestrew commented 1 year ago

This is a pretty weird bug. I experience this on nightly 801ac2acc but rolling back to 339011f59 seemed to have solved the issue for me. But even when I was experiencing this issue, it was not consistent so I couldn't even really do a git bisect. Even if I could, clearly people have been experiencing this as early as 0.7.

theoribeiro commented 1 year ago

In my case, the behavior only happened when I had the Codium plugin enabled. I ended up finding out it was a call to a redraw of the status line that for some reason interfered with the mode after leaving Telepresence. Disabling the redraw line solved it but I'm afraid this is just a symptom of some other problem with Telepresence.

ttytm commented 1 year ago

@theoribeiro you mean Codeium? If so, is your observation that it was a call to redraw the status line that Codeium made or telescope?

theoribeiro commented 1 year ago

@tobealive yes, sorry I misspelled it, I meant Codeium.

Codeium was making a call to redraw the status line, which caused files opened with Telescope to be opened in Insert mode for me. As soon as I commented that line in Codeium it started working properly again.

See https://github.com/Exafunction/codeium.vim/issues/80

rockyzhang24 commented 1 year ago

Confirmed that this issue happened after I installed nvim-treesitter-context. That's weird.

mudox commented 1 year ago

The neovim nightly-build has this issue, I changed back to 0.9.0 release, the issue gone!

mehalter commented 1 year ago

I can confirm I'm also experiencing this in Telescope as well. It appears the mode is always reflected in the buffer I open as my previous mode in Telescope. So if I have the prompt in insert mode and select a file, I end up in insert mode. If I go to normal mode in the prompt and select a file, I end up in normal mode. Using the autocommand described above is working great for now, but definitely hoping this gets fixed upstream!

catgoose commented 1 year ago

Looks like this starts with https://github.com/neovim/neovim/commit/d52cc668c736ef6ca7ee3655a7eb7fe6475afadc

mehalter commented 1 year ago

Looks like this starts with neovim/neovim@d52cc66

I can confirm this as well after doing git bisect

d52cc668c736ef6ca7ee3655a7eb7fe6475afadc is the first bad commit
commit d52cc668c736ef6ca7ee3655a7eb7fe6475afadc
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Mon Apr 10 07:33:26 2023 +0800

    vim-patch:9.0.1443: ending Insert mode when accessing a hidden prompt buffer (#22984)

    Problem:    Ending Insert mode when accessing a hidden prompt buffer.
    Solution:   Don't stop Insert mode when it was active before. (closes vim/vim#12237)

    https://github.com/vim/vim/commit/05a627c3d4e42a18f76c14828d68ee4747118211

    Co-authored-by: Bram Moolenaar <Bram@vim.org>

 src/nvim/autocmd.c                            |  6 ++++++
 src/nvim/autocmd.h                            |  1 +
 test/functional/legacy/prompt_buffer_spec.lua |  6 ++++++
 test/old/testdir/test_prompt_buffer.vim       | 11 +++++++++++
 4 files changed, 24 insertions(+)
rockyzhang24 commented 1 year ago

@mehalter @catgoose I can confirm the issue caused by that commit as well. Not sure it should be fixed on neovim, or telescope.

catgoose commented 1 year ago

@mehalter @catgoose I can confirm the issue caused by that commit as well. Not sure it should be fixed on neovim, or telescope.

Yeah, I'm not sure either. Do we flip a coin?

rockyzhang24 commented 1 year ago

Lol. At least this issue should be reopened.

Shougo commented 1 year ago

So it should be reported in upstream.

Shougo commented 1 year ago

I have reported the change and it is to fix other plugins issues. Please see https://github.com/neovim/neovim/issues/22924 So the fix is conflicted...

Shougo commented 1 year ago

Please see my comment.

https://github.com/nvim-telescope/telescope.nvim/issues/2501#issuecomment-1541009573

Zeioth commented 1 year ago

Currently hapens to me in neovim-git. neovim from arch repos doesn't have the issue.

Shougo commented 1 year ago

Because the behavior is changed in recent commit. Please see my comment.

Conni2461 commented 1 year ago

i'll keep this closed in favor of https://github.com/nvim-telescope/telescope.nvim/issues/2501, no need to have two issues open, so please report/subscribe to that issue instead. I am going to look into if, we (telescope) can work around that until there is a solution upstream, or maybe that now intended behavior ...

searleser97 commented 1 year ago

Yep that's a bit mind mind boggling. It's hard to track to what is actually causing it.

Also, calling "stopinsert" doesn't seem to work, even when scheduling it. So not an optimal but at least consistent quickfix Im using for now which works with the latest nvim version is:

nx.au({ -- Prevent entering buffers in insert mode.
  "WinLeave",
  callback = function()
      if vim.bo.ft == "TelescopePrompt" and vim.fn.mode() == "i" then
          vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "i", false)
      end
  end,
})

Version without using nx plugin, just paste the following in "init.lua"

vim.api.nvim_create_autocmd("WinLeave", {
  callback = function()
    if vim.bo.ft == "TelescopePrompt" and vim.fn.mode() == "i" then
      vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "i", false)
    end
  end,
})