Vim autocmd to apply a user defined command to multiple specific (by filetype) tabpages?

Tag: vim , vimrc , autocmd Author: comeli12345 Date: 2012-03-04

I open my Vim session with multiple tabpages simultaneously. Some of my tabpages are .txt files, some are not.

I have created, in my .vimrc, a command named Tran which refers to syntax.vim where are defined a few specific syntax highlightings for my .txt files.

:command Tran :source syntax.vim

My problems/questions :

1) When I open my Vim session, I would like to have all my .txt files highlighted thanks to the Tran command. I tried (in my .vimrc) :

:command Tran :source syntax.vim
autocmd filetype txt :Tran

… and failed.

2) For the time being, when I switch to a .txt tabpage, I immediately type the following command :


and it works. But if I go to another tabpage, and later come back to my .txt tabpage (during the same session), all the highlighting has disappeared.

I suppose those 2 problems can be solved in 1 simple way. But which one ?

Thanks in advance.

Other Answer1

Latest version of Vim makes filetype=text in .txt file. And, you can use Syntax event for this purpose. Try the following.

autocmd Syntax text :Tran


Tried your suggestion : it has no effect (neither good nor bad). Perhaps "something rotten" in my .vimrc ? Thanks, anyway.
filetype=text was added in recently. If your Vim is not support it, put a following file in ~/.vim/ftdetect/text.vim autocmd BufReadPost,BufNewFile *.txt setlocal filetype=text