The documentation says:
<afile> When executing autocommands, is replaced with the file name
for a file read or write.
<abuf> When executing autocommands, is replaced with the currently
effective buffer number (for ":r file" and ":so file" it is
the current buffer, the file being read/sourced is not in a
buffer).
<amatch> When executing autocommands, is replaced with the match for
which this autocommand was executed. It differs from
<afile> only when the file name isn't used to match with
(for FileType, Syntax and SpellFileMissing events).
Yet, if I had this autocmd:
autocmd BufNewFile * echo expand('<amatch>') expand('<afile>')
And opened, say .zshrc in /tmp (cd /tmp; vim .zshrc), I get:
/tmp/.zshrc .zshrc
They are not the same. What's going on?
% is faithful to what I actually typed. vim ./.zshrc with expand('%') added to the above autocmd gives me:
/tmp/.zshrc .zshrc ./.zshrc
<afile>is only the filename whereas<amatch>is the complete path for the file ? – nobe4 Aug 26 '15 at 06:39%, however, is faithful to whatever I actually mentioned. But I'm not sure I can trust%here. :/ – muru Aug 26 '15 at 06:40vim /tmp/.zshrcthey're the same strings. If your cwd is/tmpyou will get an absolute path, and a relative path, and while they are not the same strings, they are the same paths. – Martin Tournoij Aug 26 '15 at 06:40vim .zshrc– muru Aug 26 '15 at 06:41expand('<amatch>') == expand('%:p')andexpand('<afile>') == expand('%'). What do you think ? Edit: Just saw your edition, theexpand('<afile>') == expand('%')doesn't apply anymore – nobe4 Aug 26 '15 at 06:43<amatch>the pattern match of the autocmd? If you useBufNewFileit will be the filename; apparently absolute from your examples. ForFileTypeit should then be the matched file type:zshfor your example if you replaceBufNewFilewithFileType. – tokoyami Aug 26 '15 at 10:14<amatch>differ from<afile>in cases other than those specified in the docs? So,FileTypeis pretty much irrelevant. – muru Aug 26 '15 at 10:17