nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

Terminal title flickers when completion menu opens

Open adrian5 opened this issue 4 years ago • 31 comments

How to reproduce

Enable vim title property, e.g.:

vim.opt.title = true
vim.opt.titlestring = "%F %r"

Then use nvim-cmp and watch title flicker (update to empty, then back to titlestring presumably) each time the popup menu opens.


The only fix is to not set the title option, lazyredraw alas does not have the desired effect.

This did not happen until recently and might be related to #289. It's sufficiently annoying, not "personal preference" territory.

adrian5 avatar Oct 09 '21 14:10 adrian5

Same problem on my end, and I believe this is a indeed duplicate of #289

dmitmel avatar Oct 09 '21 15:10 dmitmel

In Gnome terminal and Neovim 0.6 master the title changes from the actual name of the file to [no name] - NVIM and back again as you select things.

David-Else avatar Oct 09 '21 19:10 David-Else

My next task is this. But it is a bit difficult. I didn't know the reason yet.

hrsh7th avatar Oct 10 '21 03:10 hrsh7th

Hm... I think we can't fix it because native lsp's hover feature also causes this...

hrsh7th avatar Oct 10 '21 03:10 hrsh7th

In lsp's hover feature, the title flickers for maybe a millisecond and returns back to the original title. But in cmp's case, the filename remains as [No Name] until I type something or select any completion item.

khaveesh avatar Oct 10 '21 21:10 khaveesh

I think we can't fix it because native lsp's hover feature also causes this...

Hmm, I see. I'll check if there's a report for this with (n)vim. I imagine this has something to do with the popup's buffer type overriding that of the active text buffer, thereby triggering a redraw of the title?

adrian5 avatar Oct 10 '21 21:10 adrian5

If you set title then titlestring gets evaluated in the floating/popup windows' context. Since this may not have a file attached (or the "wrong" one), you see [No Name]. You can test/work-around this by evaluating a function in titlestring that returns the (cached) filename value if the current context is a floating/popup windows (with no file attached).

stormc avatar Oct 11 '21 14:10 stormc

PR welcome. I have no idea for it...

hrsh7th avatar Oct 11 '21 17:10 hrsh7th

This is a fast hack to demonstrate it (I made titlestring longer so that you have time to notice the flicker, you can also introduce a synthetic delay):

set title
lua << EOF
function titlestring_file()
    if vim.api.nvim_win_get_config(0).relative ~= "" then
        return vim.t.titlestring_file or ""
    end
    local fname = vim.fn.expand('%:p:~:.')
    vim.t.titlestring_file = fname
    return fname
end
EOF
let &titlestring="%{v:lua.titlestring_file()}   %<{%{fnamemodify(getcwd(), ':~')}}  - VIM"

I don't know how to reasonably integrate this in to nvim-cmp as it has to parse/know/mess with the user-set titlestring then. Probably this is something for the documentation/wiki instead of code?

stormc avatar Oct 12 '21 07:10 stormc

Can you upload the video for the flicker?

Shougo avatar Oct 12 '21 07:10 Shougo

Hm... I cannot reproduce the problem. The reproduce instruction is needed.

Shougo avatar Oct 12 '21 07:10 Shougo

set title
set titlestring="%F %r"

And then invoke completion with nvim-cmp on the named buffer.

hrsh7th avatar Oct 12 '21 07:10 hrsh7th

@Shougo If you don't see the flicker with the code snippet above, then it "solves" it :) So, it does not reproduce the flicker but instead shows how to avoid it, sorry for the inaccuracy.

stormc avatar Oct 12 '21 07:10 stormc

Oh, so please test the latest nvim-cmp. If it is not occurred, the issue should be closed.

Shougo avatar Oct 12 '21 07:10 Shougo

@Shougo Still happens for me on latest commit 49acc84: nvim-title-flicker

adrian5 avatar Oct 12 '21 13:10 adrian5

Please upload the minimal vimrc. I cannot reproduce your problem.

Shougo avatar Oct 13 '21 00:10 Shougo

Here is my config.

if &compatible
  set nocompatible
endif

set runtimepath+=~/src/nvim-cmp
set runtimepath+=~/src/cmp-buffer
set runtimepath+=~/src/cmp-buffer/after

set completeopt=menu,menuone,noselect

filetype plugin indent on

lua <<EOF
  local cmp = require'cmp'

  cmp.setup({
    -- You can set mappings if you want
    mapping = {
      ['<C-p>'] = cmp.mapping.select_prev_item(),
      ['<C-n>'] = cmp.mapping.select_next_item(),
      ['<C-d>'] = cmp.mapping.scroll_docs(-4),
      ['<C-f>'] = cmp.mapping.scroll_docs(4),
      ['<C-Space>'] = cmp.mapping.complete(),
      ['<C-e>'] = cmp.mapping.close(),
      ['<CR>'] = cmp.mapping.confirm({
        behavior = cmp.ConfirmBehavior.Insert,
        select = true,
      }),
      ['<Tab>'] = function(fallback)
        if cmp.visible() then
          cmp.select_next_item()
        else
          fallback()
        end
      end,
    },

    -- You should specify your *installed* sources.
    sources = {
      { name = 'buffer' },
    },
  })
EOF


set title
lua << EOF
function titlestring_file()
    if vim.api.nvim_win_get_config(0).relative ~= "" then
        return vim.t.titlestring_file or ""
    end
    local fname = vim.fn.expand('%:p:~:.')
    vim.t.titlestring_file = fname
    return fname
end
EOF
let &titlestring="%{v:lua.titlestring_file()}   %<{%{fnamemodify(getcwd(), ':~')}}  - VIM"

Please tell me something wrong.

Shougo avatar Oct 13 '21 00:10 Shougo

I cannot reproduce your problem.

Did you try with titlestring = "%F %r"?

  • Your vimrc with "%F %r" gives me a title stuck in [No Name] (as others described)
  • My (full) vimrc with your custom titlestring + function resolved the flicker issue

But does that mean there's no issue? If one argues that nvim-cmp is already far from vanilla vim, and one cannot expect everything to work without small hacks, then fair enough. Otherwise I'd say it should play nice with regular vim configurations.


Either way, the workaround with a title function works well for me, I get no more flickering that way. I'll leave it up @hrsh7th to decide if this issue should be closed. If so, we should point out the workaround in the Wiki or README, to save others a headache.

adrian5 avatar Oct 14 '21 13:10 adrian5

OK. The problem is reproduced when let &titlestring="%F %r".

Shougo avatar Oct 14 '21 22:10 Shougo

nvim_win_set_option() causes the problem. And I think it cannot be fixed. Because nvim_win_set_option() is needed.

Shougo avatar Oct 14 '21 22:10 Shougo

I agree. My filename-caching titlestring function above is a hack/workaround to this problem. And it's too broad in using the cached filename unconditionally for all floating windows (condition: vim.api.nvim_win_get_config(0).relative ~= ""). This problem also extends to other than filename information you may put in titlestring that is different in the buffer and the floating window.

What would be needed for a real solution is a flag or something to tell nvim not to render titlestring for a particular window/popup, maybe set by a nvim_win_set_option() option. But that's a nvim-core change...

stormc avatar Oct 15 '21 08:10 stormc

@stormc Sorry, I totally missed your earlier post in this thread when I wrote my response to Shougo, my musings might seem a bit redundant in that context.

adrian5 avatar Oct 15 '21 12:10 adrian5

@adrian5 No worries, I think it still helped to come to a common understanding (and workaround) of the problem.

Question is whether the workaround should be documented in the wiki (as we cannot do something generic in code) and/or whether to pursue the necessary change for a real fix in nvim-core?

stormc avatar Oct 15 '21 13:10 stormc

I think this issue was fixed by latest nvim.

hrsh7th avatar Feb 16 '22 12:02 hrsh7th

I think this issue was fixed by latest nvim.

I'm on current master v0.7.0-dev+1093-g9ef569613 and the flicker still happens when not using the helper function.

adrian5 avatar Feb 16 '22 14:02 adrian5

Yes, sadly, this issue still persists...

https://user-images.githubusercontent.com/14960414/179118728-4f4822a0-66ac-4a67-93b1-63521d011ec4.mp4

charbelnicolas avatar Jul 14 '22 23:07 charbelnicolas

I have tested the behavior, but I cannot reproduce the flicker. You need to upload the minimal init.vim.

Shougo avatar Jul 15 '22 00:07 Shougo

OK. I have reproduced. When the first item is inserted with the documentation, it will be [No name]. I don't know why though.

Shougo avatar Jul 15 '22 01:07 Shougo

https://github.com/hrsh7th/nvim-cmp/issues/309#issuecomment-941035010

When no documentation source candidates, the flicker does not exist. So the original problem is improved.

https://github.com/hrsh7th/nvim-cmp/issues/309#issuecomment-1041458350

The fixed is true. It is another problem.

Shougo avatar Jul 15 '22 01:07 Shougo

Yeah, when adding and attaching an LSP it flickers, otherwise it works correctly:

https://user-images.githubusercontent.com/14960414/179129083-05f21646-1724-4683-8330-7a02f2f00575.mp4

charbelnicolas avatar Jul 15 '22 01:07 charbelnicolas

#309 (comment)

When no documentation source candidates, the flicker does not exist. So the original problem is improved.

#309 (comment)

The fixed is true. It is another problem.

Hey @Shougo, do you know if there is a way to disable the documentation pop up?

charbelnicolas avatar Jul 15 '22 16:07 charbelnicolas

It is documented.

How to disable the documentation window?~

  Simply use the following config:
>
  cmp.setup.filetype({ 'markdown', 'help' }, {
    window = {
      documentation = cmp.config.disable
    }
  })
<

Shougo avatar Jul 17 '22 05:07 Shougo