vim autocommand doesn't run when opening file
I'm using QuickCursor for entering text to forms.
My problem with that is I always have MacVim open, and with hidden
enabled, so when I :wq
from the temp file QuickCursor开发者_开发百科 make, the buffer stays in MacVim, so I have to delete it to get QuickCursor paste back to the window.
I wanted to solve this with an autocommand in my vimrc:
autocmd BufRead "/private/var/folders/fg/gv_*/T/*" set bufhidden="delete" | startinsert!
but this never run. What could be the problem ? What is the right event to use ? I tried BufWinEnter, BufNewFile, neither of them works, or maybe something else is the problem.
Ok, after several hours of try, I finally found out.
I had added quotes to the bufhidden
setting and the filename. It should be:
autocmd BufRead /private/var/folders/fg/gv_*/T/* set bufhidden=delete | startinsert!
With the extra quotes it doesn't work:
- "delete" is an invalid option value (see
:he bufhidden
) - quotes around a filename prevent the wildcards (glob characters) from matching (see doc)
If anybody else using QuickCursor, you can fine-tune it:
autocmd BufWinEnter /private/var/folders/fg/gv_*/T/* set bufhidden=delete |
exe "normal G$" | startinsert!
So it changes to insert mode at the end of the text
精彩评论