您的位置:首页 > 编程语言 > PHP开发

ubuntu下修改 vim 配置 将 .inc 后缀文件 动态当作不同文件对待的解决办法

2011-11-03 11:25 531 查看
搜做vim安装目录下的filetype.vim 文件

我的是/usr/share/vim/vim72/filetype.vim

打开它 搜索inc

我的找到如下: 1360-1365是我后来添加的。

从1347可以看出是把.inc文件当作什么格式去解析高亮语法

后面是一个函数call s:FTinc()

其中意思就是在文件的前3行 getline(1).getline(2).getline(3) 发现有XX字符串存在 那个就当作什么文件

我的处理是前3行出现 '/\* *filetype *= *cpp *\*/' 或者'/\* *filetype *= *c *\*/'  '# *filetype *= *make *' 分别当作什么文件

当然如果同时出现上面的情况是以最后一次出现的为准——状态机。

好了不多说了,希望对大家有帮助。

1346 " Povray, PHP or assembly
1347 au BufNewFile,BufRead *.inc         call s:FTinc()
1348
1349 func! s:FTinc()
1350   if exists("g:filetype_inc")
1351     exe "setf " . g:filetype_inc
1352   else
1353     let lines = getline(1).getline(2).getline(3)
1354     if lines =~? "perlscript"
1355       setf aspperl
1356     elseif lines =~ "<%"
1357       setf aspvbs
1358     elseif lines =~ "<?"
1359       setf php
1360     elseif lines =~ '/\* *filetype *= *cpp *\*/'
1361       setf cpp
1362     elseif lines =~ '/\* *filetype *= *c *\*/'
1363       setf c
1364     elseif lines =~ '# *filetype *= *make *'
1365       setf make
1366     else
1367       call s:FTasmsyntax()
1368       if exists("b:asmsyntax")
1369     exe "setf " . fnameescape(b:asmsyntax)
1370       else
1371     setf pov
1372       endif
1373     endif
1374   endif
1375 endfunc
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vim ubuntu assembly exe php 360