For situations where you need for vim to have fully loaded up as if you started it manually, this works:
vim -c "autocmd! CursorHold * <commands to run>"
For example, I wanted to redirect the output of :map
to a file from the shell, but I wanted to capture the mapping that vim-airline creates only after it's displayed its tabline (line at top showing all buffernames open.) Because it seems to do this asynchronously, simply running a -c
redirect to a file wasn't giving it time to make the mappings. There could be a better way, but this works for me, especially since I already have updatetime
set to 100
(0.1 seconds), which affects how long until the CursorHold
event fires. By default, vim sets it to 4 seconds.
vim -c "autocmd! CursorHold * set nomore | redir! > mapNew | map | redir END | q"