How can one set the text of the command line in command mode? So when it is not in use? Same as the message that appears when writing a file? I'm looking for a solution for vim and/or nvim, preferably nvim
2 Answers
With your affirmative reply to my comment I believe I have a handle on what you are looking for. Basically you want a custom message to always occupy the command line when nothing else is happening there.
The fundamental way to populate the command line with arbitrary text is just :echo
(or one of its variants). :echo "hello world"
, for example.
I'm sure you could do something sophisticated with, let's say, a function and a timer where the timer periodically calls the function to call :echo
after checking for certain conditions (e.g. making sure the command line isn't active).
For a poor man's solution, though, you could use autocmd
and various, appropriate event types and have them emit the message. The idea is to pick events that hopefully nicely fill the gaps of those times when you aren't on the command line. For example, add this to your vimrc and you'll find that the message "Hello!" pretty consistently occupies the commmand line...
augroup cmdlinemsg
let g:cmdmsg="Hello!"
autocmd!
au CursorMoved * :echo g:cmdmsg
au CursorHold * :echo g:cmdmsg
au TextChanged * :echo g:cmdmsg
au TextChangedI * :echo g:cmdmsg
augroup END
I didn't check this for side effects or potentially negative impacts on too many Vim actions except for basic editing and navigation but this might get you started on the right path...at least until someone posts that function/timer thingy. :)
Update: I was repeatedly muttering "hack!" under my breath when I began toying with this idea. And I didn't spend too much time choosing the event types. But so far, exactly as typed above, it's working surprisingly well! (At least until someone comes along and says "Uh, dude, you forgot about X.")
:echo "some text"
? Or something more permanent?:
is pressed and the c/l is in use. @mike?