Reputation: 654
I try to write a simple function in my .vimrc
, accessable by a mapping.
This function should use the YankRing plugin. Therefore it first open a window with the YankRing buffer, if not open yet. I could confirm the functionality of each part in that function, but as soon as I define any command after the window open, it will be executed first and just after all, the window is opened. In fact it seems like something happen, cause the buffer status (name, line, col, ...) appears in the command line, but the window with the buffer itself does not open.
Here is a minimal example, using a sleep
as following command, that leads to the delay of the window opening:
function! s:foo()
execute('YRShow 0') " Opens the YankRing window, if not already open.
echo 'bar' " Just to have some visual reference.
sleep 3 " Show the delay of the window open and the echo message.
endfunction
Observed behaviour:
First, the command line gets this buffer status information content. Immediately afterwards, the echo
message is shown. Then after the 3s delay, the window is opened.
Expected behaviour:
Open the window. Show the message and wait 3s.
Anybody who understand what is happening here? For my function the user needs to watch the window content, before he can interact.
Thanks!
Upvotes: 1
Views: 1183
Reputation: 172520
Some plugin mappings and commands are asynchronous. Vim has an event system; cp. :help autocommand
. In that case, you have to hook into the appropriate events (:help autocmd-events
). For plugins, these often are BufNew
or FileType
.
With mappings, these are just like typed commands, and inserted in an input buffer. To asynchronously execute mappings after any other pending commands, the feedkeys()
function can be used. Do this only when necessary, as its use interferes with macro recording and command repeats!
I had a brief look at the YankRing code. The :YRShow
functionality seems to be straightforward, synchronous code. The effect you are experiencing may be that the contents aren't yet drawn while your function is executing. You can enfore a screen update via :redraw
, before the :sleep
command.
Upvotes: 3