1

Preface: I might be asking the wrong question, so I'll just say what my problem is first.

Whenever I use ^Z to background vim, then later (can be hours later) run fg to bring it back, YouCompleteMe doesn't do any completion (however, it does sometimes say below the status line that it needs to be restarted)

A workaround has been to run :YcmRestartServer whenever I foreground vim manually, but I'd like to have that run automatically (if it isn't already running).

1
  • I’ll search later, but afaik there are no auto events for this, although presumably source code could be modified to allow it? A SIG event handler for the right thing, maybe?
    – D. Ben Knoble
    Apr 8 '20 at 1:34
0

So setting aside that there may be an issue with YCM, you can put the following in your .vimrc.

augroup RestartYCM
  autocmd!
  autocmd FocusGained * :YcmRestartServer
augroup END
4
  • According to the docs vimhelp.org/autocmd.txt.html#FocusGained the FocusGained event only works for GUI Apr 9 '20 at 21:55
  • Maybe. If true, however, I tested it with gvim and it works a treat. Apr 10 '20 at 18:09
  • I'm accepting this, not because it works for every solution, but because it works for GUI, at least, and it was, in fact, a problem with YCM that appears to be patched, so I can't easily test this anymore. Apr 15 '20 at 22:58
  • Great! I actually have a Q for @D._Ben_Knoble, who apparently edited the response to include the (superior) autocommand group. I considered including the autocommand group originally, but did not under the assumption it was not strictly necessary. Would you say that (unless otherwise contraindicated) you would always include groups, or similar "best practices" in responses? Apr 16 '20 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.