Closed ifelsemaybe closed 2 months ago
Here's how I've tried to solve it - hope it's useful:
-- Consolidated list of characters that should toggle ghost_text
local toggle_chars = {
'"', "'", '`', '<', '>', '{', '}', '[', ']', '(', ')', ' ', ''
}
local cmp_config = require('cmp.config')
local function toggle_ghost_text()
if vim.api.nvim_get_mode().mode ~= "i" then
return
end
-- Get the current cursor column and line content
local cursor_col = vim.fn.col('.') -- Get cursor column
local line = vim.fn.getline('.') -- Get current line content
-- Get the character after the cursor
local char_after = line:sub(cursor_col, cursor_col)
-- Check if the character after the cursor is in the toggle list (pair characters, spaces, or end of line)
local should_enable_ghost_text = vim.tbl_contains(toggle_chars, char_after)
-- Enable or disable ghost_text based on the conditions
cmp_config.set_onetime({
experimental = {
ghost_text = should_enable_ghost_text,
},
})
end
vim.api.nvim_create_autocmd({ "InsertEnter", "CursorMovedI" }, {
callback = toggle_ghost_text,
})
Yea, thanks a bunch. This solves my issue.
This works like a charm. Wonder if I can get it to work for all auto-completion in general, meaning also for the pop-up item menu.
Thanks again, Wishing you a happy weekend!
I found the answer to my question above, for the completion menu.
I just put the value of "should_enable_ghost_text" inside of the "enable" property of the cmp.config, and it works!
Hello,
I've noticed adding new characters within an already existing word still triggers ghost text. The downside of this is the confusion led by extra ghost characters appearing within the same word you are editing.
Has anybody managed to find an easy solution through the lua config, or is this something that needs fixing, within the codebase, through a pull request?
Would greatly appreciate any insights pertaining to this issue.
Picture for reference:
(I added the character f inside the word Function, and some ghost text appears)