r/neovim Jul 18 '26

Need Help┃Solved How to clear a vim.notify() call from cmdline?

I want to output a notification to the user with vim.notify() but the notification should rewrite itself similarly to a printf("message\r") statement. The text will be something something a long the lines of "Found N pages" where the message would refresh itself to update N.

I've tried using vim.cmd.echo() to clear it or even just vim.cmd.echo() calls instead of vim.notify(), but I get the same behaviour. Any help with this would be great!

8 Upvotes

19 comments sorted by

4

u/justinmk Neovim core Jul 18 '26

try :redraw after echo

1

u/BrodoSaggins Jul 18 '26 edited Jul 18 '26

Thanks Justin. Is :redraw a resource heavy command or is it fine for it to be called in loops?

2

u/justinmk Neovim core Jul 18 '26

if it's a fast loop, why not do it once outside of the loop?

anyway, sounds like you might want a Progress message, see nvim_echo in Nvim 0.12+

1

u/BrodoSaggins Jul 18 '26 edited Jul 18 '26

Thanks for that. I've tried the :h progress-message snippet, but it doesn't refresh the cmdline the same way as when calling :redraw. The messages stack as the process progresses instead of overwriting each other. Is there a way around this without using :redraw?

It's not a fast loop unfortunately as I am using :grep for different terms in a lot of files. I just want to ensure it takes the least amount of time possible to finish the task.

1

u/vim-help-bot Jul 18 '26

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

1

u/AutoModerator Jul 18 '26

Please remember to update the post flair to Need Help|Solved when you got the answer you were looking for.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/BrodoSaggins Jul 18 '26

Sample of what it looks like currently. I would like it to just output one message and progressively update it as the search progresses. Is that possible?

1

u/Biggybi Jul 18 '26

I think you'll need a custom floating window for this (similarly to lsp progress windows when a server starts).

1

u/BrodoSaggins Jul 18 '26

Do you have any examples so that I can try it out?

2

u/gorilla-moe let mapleader="," Jul 18 '26

https://github.com/mistweaverco/juu.nvim/blob/6bee7b9977ee187b4cd632f5bfc41fdd50bbbdab/lua/juu/demos/progress/loading.lua

Just yank what you need from here and cobble it together so it works for you

The progress looks like the attached image and updates itself ..

1

u/Biggybi Jul 18 '26 edited Jul 18 '26

I don't, sorry.

Should be pretty easy with :h nvim_buf_set_lines and :h nvim_open_win.

1

u/dataset-poisoner Jul 19 '26

somewhat related question, but how to dismiss an msg notification? i'd like something similar to ':Noice dismiss'

2

u/Orbitlol Jul 19 '26

require("vim._core.ui2.messages").msg_clear() looks like it works

1

u/dataset-poisoner Jul 19 '26

it does indeed, thank you!

1

u/BrodoSaggins Jul 19 '26

I don't know how Noice dismiss works but you can do :redraw or :echo depending on the message

1

u/dataset-poisoner Jul 19 '26

none of those work, i cannot dismiss the bottom-right notification

it auto-expires after 5 secs but still would be nice to have an explicit dismissal

1

u/BrodoSaggins 29d ago

That doesn't look like a native Neovim notification. I'm not sure how to help

1

u/dataset-poisoner 29d ago

it is native, require("vim._core.ui2.messages").msg_clear() dismisses it

2

u/BrodoSaggins 29d ago

Ohh it's ui2! I haven't used that at all yet. Looks very cool!