0

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

  • What do you mean with "set text", exactly? Just :echo "some text"? Or something more permanent? – Martin Tournoij Dec 20 '17 at 23:32
  • I'm reading "when it is not in use" to mean something that is always present on the c/l unless : is pressed and the c/l is in use. @mike? – B Layer Dec 21 '17 at 4:00
  • @BLayer exactly, write to it, when nothing else writes there – mike Dec 21 '17 at 12:16
  • Um, why? This is what the statusline was built for. – D. Ben Knoble Dec 21 '17 at 15:49
1

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.")

0

:echo "text"

does it. Read :help :echo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.