How does Vim's autoread work?

后端 未结 7 1658
[愿得一人]
[愿得一人] 2021-01-30 10:13

:h autoread says:

When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically

相关标签:
7条回答
  • 2021-01-30 10:41

    Outside of gvim, autoread doesn't work for me.

    To get around this I use this rather ugly hack.

    set autoread
    augroup checktime
        au!
        if !has("gui_running")
            "silent! necessary otherwise throws errors when using command
            "line window.
            autocmd BufEnter        * silent! checktime
            autocmd CursorHold      * silent! checktime
            autocmd CursorHoldI     * silent! checktime
            "these two _may_ slow things down. Remove if they do.
            autocmd CursorMoved     * silent! checktime
            autocmd CursorMovedI    * silent! checktime
        endif
    augroup END
    

    This seems to be what the script irishjava linked to does, but that lets you toggle this for buffers. I just want it to work for everything.

    0 讨论(0)
  • 2021-01-30 10:48

    Trigger when cursor stops moving

    Add to your vimrc:

    au CursorHold,CursorHoldI * checktime
    

    By default, CursorHold is triggered after the cursor remains still for 4 seconds, and is configurable via updatetime.

    Buffer change trigger

    To have autoread trigger when changing buffers, add to your vimrc:

    au FocusGained,BufEnter * checktime
    

    Terminal window focus trigger

    To have FocusGained (see above) work in plain vim, inside a terminal emulator (Xterm, tmux, etc) install the plugin: vim-tmux-focus-events

    On tmux versions > 1.9, you'll need to add in .tmux.conf:

    set -g focus-events on
    
    0 讨论(0)
  • 2021-01-30 10:56

    A bit late to the party, but vim nowadays has timers, and you can do:

    if ! exists("g:CheckUpdateStarted")
        let g:CheckUpdateStarted=1
        call timer_start(1,'CheckUpdate')
    endif
    function! CheckUpdate(timer)
        silent! checktime
        call timer_start(1000,'CheckUpdate')
    endfunction
    
    0 讨论(0)
  • 2021-01-30 10:59

    As per my posting on superuser.com

    Autoread just doesn't work. Use the following.

    http://vim.wikia.com/wiki/Have_Vim_check_automatically_if_the_file_has_changed_externally

    I got the best results by calling the setup function directly, like so.

    let autoreadargs={'autoread':1} 
    execute WatchForChanges("*",autoreadargs) 
    

    The reason for this, is that I want to run a ipython/screen/vim setup.

    0 讨论(0)
  • 2021-01-30 11:00

    Autoread does not reload file unless you do something like run external command (like !ls or !sh etc) vim does not do checks periodically you can reload file manually using :e

    More details in this thread: Click here

    0 讨论(0)
  • 2021-01-30 11:01

    for me it works when i use the command

    :set autoread
    

    Of course you have to save the file in the other editor before anything happens.

    0 讨论(0)
提交回复
热议问题