简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM