1

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 :

:Tran

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.

ThG
  • 2,361
  • 4
  • 22
  • 33

1 Answers1

1

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
thinca
  • 126
  • 2
  • Tried your suggestion : it has no effect (neither good nor bad). Perhaps "something rotten" in my .vimrc ? Thanks, anyway. – ThG Mar 20 '12 at 18:29
  • 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 – thinca Mar 21 '12 at 17:34