Overwriting an autocmd for a particular filetype

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
ds
Reply | Threaded
Open this post in threaded view
|

Overwriting an autocmd for a particular filetype

ds
Hi!


Let's say I have an autocmd defined in my .vimrc, which applies to every possible buffer (autocmd-pattern is set to *). Now, is there any way to override this autocmd only for a particular filetype? I mean, to disable this "general" autocmd and to use another one instead? With the help of after/ftplugin, probably?

(Wrapping this autocmd in augroup, and then resetting it in after/ftplugin/myfiletype.vim with autocmd! overwrites it globally, of course. Is there a less destructive way? Would be grateful for a hint :)


Thanks.


--
ds

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overwriting an autocmd for a particular filetype

Christian Brabandt

On Di, 01 Mai 2018, ds wrote:

> Hi!
>
>
> Let's say I have an autocmd defined in my .vimrc, which applies to every possible buffer (autocmd-pattern is set to *). Now, is there any way to override this autocmd only for a particular filetype? I mean, to disable this "general" autocmd and to use another one instead? With the help of after/ftplugin, probably?
>
> (Wrapping this autocmd in augroup, and then resetting it in after/ftplugin/myfiletype.vim with autocmd! overwrites it globally, of course. Is there a less destructive way? Would be grateful for a hint :)

perhaps you can use the 'eventignore' option or the ':noa' command
modifier. I am not aware of a buffer-specific solution.


Best,
Christian
--
Wie man sein Kind nicht nennen sollte:
  Anna Log

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
ds
Reply | Threaded
Open this post in threaded view
|

Re: Overwriting an autocmd for a particular filetype

ds
Christian, thanks for your reply!

What would you say about such a scheme:

First, I have this defined in my .vimrc:

```VIMRC```
augroup MyAutoCmd
    autocmd!
    autocmd MyORIGINALFancyAutoCmdHere
augroup END
```VIMRC END```

Second, these triggers are present in the filetype-specific settings

```after/ftplugin/somefiletype.vim```
function! NewCmdOn()
    augroup MyAutoCmd
        autocmd!
        autocmd MyNEWFancyAutoCmdHere
    augroup END
endfunction
autocmd! BufEnter,WinEnter,TabEnter <buffer> call NewCmdOn()

function! NewCmdOff()
    augroup MyAutoComp
        autocmd!
        autocmd MyORIGINALFancyAutoCmdHere
    augroup END
endfunction
autocmd! BufLeave,BufDelete <buffer> call NewCmdOff()
```after/ftplugin/somefiletype.vim END```

Now, upon entering the filetype-specific buffer, the original autocmd defined in .vimrc will be reset and overwritten with the new one. And if leaving this filetype-specific buffer, it will be reset again, and then overwritten with the original one. Am I right? BufLeave and BufDelete should cover all the cases, or should I consider adding WinLeave, TabLeave, etc, too?


Thanks!


--
ds

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.