0

I have written the following mapping in my vimrc:

autocmd FileType python     :iabbrev <buffer> for for item in:<left>

After I source the python file it works. However, now whenever I type in for in the vimrc file, I get that same iabbrev behavior, even if I re-set ft=vim in that file. Why does this abbreviation occur across/outside of files I specify? Is there a way to get rid of this?

1

The keyword is <buffer>, not <filetype>.

It exactly means what it says: it affects the current buffer. Once the event has been triggered, the mapping exists in the current buffer, and it'll stay forever.

If you change the filetype, you'll just trigger another event that may define new things, and maybe override a few that already exist.

If you really plan to change the filetype of the current buffer, definitively use a ftplugin, and at the end fill the b:undo_ftplugin variable with all the things you have defined and that you wish to see undone.

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.