Wednesday, August 29, 2012

Re: Autocmds

On Tuesday, 28 August, 2012 at 04:12:26 BST, Ben Fritz wrote:
>> When I try this:
>>
>> autocmd BufRead * if &ft == 'perl' | setlocal makeprg=perl\ -cw\ % | endif
>>
>> makeprg doesn't get set, I guess because vim sets the filetype to "perl" only after BufRead has happened (the :help doesn't say). The :help does hint at using BufWinEnter instead, which works for this case, but it seems suboptimal having these autocmd commands executed every time I display the buffer, when really I only need them executed the once, after buffer read/load.
>
>The event you want for the loading of the file is FileType. As mentioned before.

But FileType autocmds get executed at every display of the buffer, not just when loading the file.

autocmd BufWinEnter * if &ft == 'perl' | exe input("BufWinEnter") | endif
autocmd FileType perl exe input("FileType")

These both wait for input when bringing forth via :b. I suppose I'd just have to set and check for a 'loaded' variable at the beginning of my commands.

--

.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment