Vim - how to run a command immediately when starting vim?

Viewed 76219

I have a plugin (FindFile.vim) that needs to run :FindFileCache . whenever I start vim to gather a file cache for quick opening.. I have to run this every time I start vim though.

How might I write a command that runs once, every time that vim starts up?

6 Answers

To get even later than other answers but still just after startup, use a timer in .vimrc. For example, this code in .vimrc waits half a second after startup before setting a variable.

function DelayedSetVariables(timer)
    let g:ycm_filetype_blacklist['ignored'] = 1
endfunction
let timer=timer_start(500,'DelayedSetVariables')

(The variable in the example is the blacklist from YouCompleteMe plugin. I assume, the plugin starts up some other process asynchronously which then creates variables, but is not quite ready by the time vim has started. The variable does not exist when I try to set it in .vimrc, an after file, or VimEnter event. This is specific to my Windows system somehow, YCM documentation says .vimrc should work for setting options.)

You can run vim file.txt "+:FindFileCache ."

Related