Wikia

Vim Tips Wiki

Changes: How to print full screen width messages

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 14: Line 14:
 
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.
 
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:
+
The WideMsg() function below prints a single-line [long] message (of up to (&columns-1) length) without the "Press Enter" prompt, guaranteed:
   
 
<pre>
 
<pre>
" WideMsg() prints [long] message up to (&amp;columns-1) length
+
" WideMsg() prints [long] message up to (&columns-1) length
 
" guaranteed without "Press Enter" prompt.
 
" guaranteed without "Press Enter" prompt.
 
function! WideMsg(msg)
 
function! WideMsg(msg)
let x=&amp;ruler | let y=&amp;showcmd
+
let x=&ruler | let y=&showcmd
 
set noruler noshowcmd
 
set noruler noshowcmd
 
redraw
 
redraw
 
echo a:msg
 
echo a:msg
let &amp;ruler=x | let &amp;showcmd=y
+
let &ruler=x | let &showcmd=y
 
endfun
 
endfun
   
 
" To test.
 
" To test.
 
:set ruler showcmd
 
:set ruler showcmd
:call WideMsg(repeat('x',&amp;co-1))
+
:call WideMsg(repeat('x',&co-1))
 
</pre>
 
</pre>
   
Line 41: Line 41:
   
 
==Comments==
 
==Comments==
 
----
 

Latest revision as of 00:11, September 30, 2008

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

Around Wikia's network

Random Wiki