Terminal title flickers when completion menu opens
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.
Same problem on my end, and I believe this is a indeed duplicate of #289
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.
My next task is this. But it is a bit difficult. I didn't know the reason yet.
Hm... I think we can't fix it because native lsp's hover feature also causes this...
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.
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?
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).
PR welcome. I have no idea for it...
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?
Can you upload the video for the flicker?
Hm... I cannot reproduce the problem. The reproduce instruction is needed.
set title
set titlestring="%F %r"
And then invoke completion with nvim-cmp on the named buffer.
@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.
Oh, so please test the latest nvim-cmp. If it is not occurred, the issue should be closed.
@Shougo Still happens for me on latest commit 49acc84:

Please upload the minimal vimrc. I cannot reproduce your problem.
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.
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.
OK. The problem is reproduced when let &titlestring="%F %r".
nvim_win_set_option() causes the problem.
And I think it cannot be fixed. Because nvim_win_set_option() is needed.
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 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 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?
I think this issue was fixed by latest nvim.
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.
Yes, sadly, this issue still persists...
https://user-images.githubusercontent.com/14960414/179118728-4f4822a0-66ac-4a67-93b1-63521d011ec4.mp4
I have tested the behavior, but I cannot reproduce the flicker. You need to upload the minimal init.vim.
OK. I have reproduced. When the first item is inserted with the documentation, it will be [No name].
I don't know why though.
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.
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
When no documentation source candidates, the flicker does not exist. So the original problem is improved.
The fixed is true. It is another problem.
Hey @Shougo, do you know if there is a way to disable the documentation pop up?
It is documented.
How to disable the documentation window?~
Simply use the following config:
>
cmp.setup.filetype({ 'markdown', 'help' }, {
window = {
documentation = cmp.config.disable
}
})
<