Wikia

Vim Tips Wiki

How to print full screen width messages

Talk0
1,610pages on
this wiki
Tip 1289 Printable Monobook Previous Next

created July 25, 2006 · complexity advanced · author Yakov Lerner · version 6.0


Sometimes, a single-line echo causes the "Press Enter" prompt even though the message is considerably shorter than screen width. This is often an inconvenience for script writers.

The WideMsg() function below prints a single-line [long] message (of up to (&columns-1) length) without the "Press Enter" prompt, guaranteed:

" WideMsg() prints [long] message up to (&columns-1) length
" guaranteed without "Press Enter" prompt.
function! WideMsg(msg)
  let x=&ruler | let y=&showcmd
  set noruler noshowcmd
  redraw
  echo a:msg
  let &ruler=x | let &showcmd=y
endfun

" To test.
:set ruler showcmd
:call WideMsg(repeat('x',&co-1))

Explanation

There are two options, 'showcmd' and 'ruler', that force the "Press Enter" prompt after messages that are shorter than screen width. Either of two options, when set, take space on the right of the bottom line.

The WideMsg() function above saves values of these two suspect options, echo the message, then restores the options.

There is no "Press Enter" prompt, and options are properly restored.

CommentsEdit

Advertisement | Your ad here

Around Wikia's network

Random Wiki