Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #1373 - Get shortened messages from using echomsg

Created: October 31, 2006 3:35 Complexity: intermediate Author: Yakov Lerner Version: n/a Karma: 2/3 Imported from: Tip#1373

vim has 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 capabilty on.


To turn this shortening on, you need two steps:

1) set shortmess+=T " add T flag to 'shortmess' option

2) use the following form of echo:

exe "norm :echomsg repeat('a',&co+10)\n"
exe "norm :echomsg LongMessage\n"


Or use the function ShortEcho() below.


The 1st step (set shortmess+=T) is straightforward, you might already have T in 'shortmess' option already.

The 2nd step is tricky. ':echo' does not shorten long messages. ':echomsg', by itself, does not shorten long messages. Only when :echomsg is used under :norm, it truncates long messages. 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

Advertisement