Progressively slower reloading time of .vimrc

后端 未结 2 1952
半阙折子戏
半阙折子戏 2021-02-18 23:07

My boot time for vim is about a half second (tested with \"--startuptime\"), but after I reload vimrc a couple times via source, it gets slower subsequently. I have

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-18 23:57

    The culprit here is your use of autocmd. When you define an auto-command with

    autocmd  
    

    vim defines a new auto command regardless of existing ones. So when you have several such auto commands in your .vimrc and repeatedly source it (in this case, for every write), you end up defining hundreds and thousands of auto commands which all do the same thing repeatedly. Very soon this will blow up and slow your vim session, which is what you've been noticing.

    What you need to do instead, is to group your auto commands and then clear the definitions for that group with autocmd!. As a simple example:

    augroup Group1  
        autocmd!
        autocmd  
        autocmd  
        ...    
    augroup END
    

    You can have as many groups as you like, which allows you to organize them by similar actions/events.

提交回复
热议问题