In some trial-and-error testing using the following two statements:

iabbrev <buffer> return NONONON
autocmd FileType python :iabbrev <buffer> return YESYESYES

It looks like regardless of specificity, the vimrc will always use the first item encountered. That is, when I open a python file and type in return, it will give me NONONON. is this a correct understanding? Are there ever any times when a later or more specific item is used, or is it always the first-encountered value used for all commands and such? Where could I find more information on the 'order of how variables are set in the vimrc and such' ?


Don't directly define buffer restricted mappings, abbreviations, commands, variables... in the .vimrc. They'll only apply to the first buffer: the one which is active when the .vimrc is loaded.

Filetype/syntax related events are triggered after the startup routine described in :h startup

  • thanks -- when would someone want to use the <buffer> restriction then? I've been following along to Vimscript the hard way and almost all mapping examples use that. – David542 Jun 11 '20 at 23:16
  • In ftplugins, or in local vimrc. I'd recommend to avoid using autocommands for defining ft-specific things: they don't scale well IMO, prefer ftplugins instead. – Luc Hermitte Jun 11 '20 at 23:22
  • thank you. Is the second command I've listed in my question an example of an ftplugin or does it literally have to be a file in that folder? – David542 Jun 12 '20 at 4:15
  • ftplugins are files. Vim already has FileType autocommands that automatically load these files. – Luc Hermitte Jun 12 '20 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.