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 6:39%
, however, is faithful to whatever I actually mentioned. But I'm not sure I can trust%
here. :/ – muru Aug 26 '15 at 6:40vim /tmp/.zshrc
they're the same strings. If your cwd is/tmp
you 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 6:40vim .zshrc
– muru Aug 26 '15 at 6: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 6:43