Vim autocommand does not start when opening a file

I use QuickCursor to enter text into forms. My problem is that I always have MacVim open and hidden enabled, so when I :wq from the temporary QuickCursor make file, the buffer remains in MacVim, so I need to delete it to get the QuickCursor paste back to the window. I wanted to solve this with autocommand in my vimrc: autocmd BufRead "/private/var/folders/fg/gv_*/T/*" set bufhidden="delete" | startinsert! autocmd BufRead "/private/var/folders/fg/gv_*/T/*" set bufhidden="delete" | startinsert! but it never starts. What could be the problem? What is the right event to use? I tried BufWinEnter, BufNewFile, none of them work, or maybe something else is a problem.

+4
source share
1 answer

Well, after several hours of trying, I finally found out.

I added quotes to the bufhidden setting and file name. It should be:

 autocmd BufRead /private/var/folders/fg/gv_*/T/* set bufhidden=delete | startinsert! 

It does not work with extra quotes:

  • "delete" - invalid parameter value (see :he bufhidden )
  • quotes around the file name prevent wildcards (glob characters) from matching (see doc )

If anyone else uses QuickCursor, you can fine tune it:

 autocmd BufWinEnter /private/var/folders/fg/gv_*/T/* set bufhidden=delete | exe "normal G$" | startinsert! 

Thus, it changes to insert mode at the end of the text

+2
source

All Articles