Reputation: 7780
Is it possible to have the statusline in Vim be updated so and so long after a given event?
And if so, how does one do that?
Upvotes: 9
Views: 2340
Reputation: 42225
As others have already pointed out, using timed changes to the statusline is not possible at the moment. However, if you can pick a suitable event at which the status reverts to the default, then you might be in luck. For e.g., if your workflow is:
Esc
out to normal mode and call your shortcutthen you could use the InsertEnter
event in an autocommand to change the status to the default once you hit i in normal mode.
Here's a small fun example that you can probably modify to your needs.
"statusline
hi green term=bold cterm=bold ctermfg=107
hi red term=bold cterm=bold ctermfg=167
hi gray term=bold cterm=bold ctermfg=0
hi lblue term=bold cterm=bold ctermfg=12
function! Palpatine()
let str='At last, the Jedi are no more'
return str
endfunction
function! Force()
let str=',~`,~`,~`,~`,~`,~`,~`,~'
return str
endfunction
function! DefaultStatus()
let statusStr='%#red#Palpatine: %#gray#%{Palpatine()} %#lblue#%{Force()} %=%#green#Yoda'
return statusStr
endfunction
set laststatus=2
set statusline=%!DefaultStatus()
function! Yoda()
let str='Not if anything to say about it, I have'
return str
endfunction
function! MyStatus()
let statusStr='%#red#Palpatine %=%#lblue#%{Force()} %#gray#%{Yoda()} %#green#:Yoda'
return statusStr
endfunction
function! MyFunc()
set statusline=%!MyStatus()
endfunction
noremap <C-m> :call MyFunc()<CR>
With the above definitions, every time I press Ctrlm, the statusline changes to the above.
Now by setting an autocommand, we can revert it to the default whenever you enter insert mode.
autocmd InsertEnter * set statusline=%!DefaultStatus()
Upvotes: 33