Vim Tips Wiki
(Remove html character entities)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 4: Line 4:
 
|previous=1370
 
|previous=1370
 
|next=1375
 
|next=1375
|created=October 31, 2006
+
|created=2006
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Yakov Lerner
 
|author=Yakov Lerner
Line 25: Line 25:
 
</pre>
 
</pre>
   
Or use the function <tt>ShortEcho()</tt> below.
+
Or use the function <code>ShortEcho()</code> below.
   
The first step (<tt>set shortmess+=T</tt>) is straightforward. You might already have T in the <tt>shortmess</tt> option already.
+
The first step (<code>set shortmess+=T</code>) is straightforward. You might already have T in the <code>shortmess</code> option already.
   
The second step is tricky. <tt>:echo</tt> does not shorten long messages. <tt>:echomsg</tt>, by itself, does not shorten long messages. Only when <tt>:echomsg</tt> is used under <tt>:norm</tt>, are long messages truncated. And don't forget trailing <tt>\n</tt> when using <tt>:exe norm</tt>.
+
The second step is tricky. <code>:echo</code> does not shorten long messages. <code>:echomsg</code>, by itself, does not shorten long messages. Only when <code>:echomsg</code> is used under <code>:norm</code>, are long messages truncated. And don't forget trailing <code>\n</code> when using <code>:exe norm</code>.
   
 
<pre>
 
<pre>

Latest revision as of 06:23, 13 July 2012

Tip 1373 Printable Monobook Previous Next

created 2006 · complexity intermediate · author Yakov Lerner · version n/a


Vim has the ability to display long echo-messages such that they are truncated in the middle to fit the line ('...' will appear in the line). But it's tricky to turn this capability on.

To turn this shortening on, you need two steps:

set shortmess+=T " add T flag to 'shortmess' option
:exe "norm :echomsg repeat('a',&co+10)\n"
:exe "norm :echomsg LongMessage\n"

Or use the function ShortEcho() below.

The first step (set shortmess+=T) is straightforward. You might already have T in the shortmess option already.

The second step is tricky. :echo does not shorten long messages. :echomsg, by itself, does not shorten long messages. Only when :echomsg is used under :norm, are long messages truncated. And don't forget trailing \n when using :exe norm.

function! ShortEcho(msg)
  " regular :echomsg is supposed to shorten long messages when shortmess+=T but it does not.
  " under "norm echomsg", echomsg does shorten long messages.
  let saved=&shortmess
  set shortmess+=T
  exe "norm :echomsg a:msg\n"
  let &shortmess=saved
endfunction

Comments[]