1

I have some autocmd triggering on TextChanged, that I want to have persisted between Vim restarts.

I could make a big if-elseif construct in the vimrc, sure, but I prefer saving the autocmd only for the specific file, as the autocmd cmd changes with each file.

Can this be done using view sessions? Do you have better ways to do this?

Thanks in advance!

3

In your ~/.vimrc, you can define an :autocmd that targets the opening of the particular file, and then define the TextChanged autocmd for the particular buffer in there:

autocmd BufRead /path/to/the/special/file autocmd TextChanged <buffer> ...
0

Two methods I can think of are:

  • initiating vim with a -u filename.vimrc for each file you want to specify the modifications with, and have it source your primary .vimrc to bring in the rest of your normal work environment.
  • creating a separate autocmd file for specific subset paths or files, then sourceing that from your main .vimrc

For the external autuocmd file:

augroup the_file_types
  autocmd!
  autocmd BufReadPost my.fun.file call MyFunction('arg1')
augroup END
autocmd BufWrite my.other.file do_something_else

The first sounds annoying to me to have to remember every time I start up the editor; the second is more versatile and less harrying.

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.