1

I'd like to lose focus when I'm in insert mode, to trigger auto-save on *.coffee buffers and also I need it to change mode from insert to normal mode to trigger Live compile feature of vim-coffee-script plguin.

What I achieved now: autocmd BufWritePost,FocusLost *.coffee :wa

But how to bring it to normal mode?

Thanks in advance.

  • As my understanding, if I have this in vimrc: autocmd BufWritePost * :<ESC> . It won't work because user needs to switch to normal mode first before be able to do the command <ES>. I'm trying to put two commands in a function. – Tuyen Pham Jun 8 '18 at 12:12
  • Remove the leading colon on :<Esc>—does that work? – D. Ben Knoble Jun 8 '18 at 14:12
  • @D.BenKnoble: I'll check it on next monday. Actually we can run multiple commands like so: autocmd FocusLost *.coffee :wa | stopinsert. But from what I've tested I have to move to another buffer in the same window (buffer1 | buffer2) to trigger normal mode in that buffer then go back to .coffee to get normal, idk why. I set mousefocus to do what I've mentioned. – Tuyen Pham Jun 8 '18 at 16:38
  • I guess I’m just confused as to why that seems necessary to get from insert to normal. It should be as simple as an Esc. shrugs not sure – D. Ben Knoble Jun 8 '18 at 16:42
  • @D.BenKnoble: I used vim-coffee-script plugin with auto-save autocmd as mentioned above and for unknown reason the feature live preview compiling - CoffeeWatch can only be triggered when .coffee saved and buffer in normal mode or just normal mode. auto-save on first post will run in background and keep buffer in insert mode. For quick testing purpose I need to paste and back to another app. – Tuyen Pham Jun 8 '18 at 17:13

Your Answer

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

Browse other questions tagged or ask your own question.