免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3580 | 回复: 7

vim配置问题请教 [复制链接]

论坛徽章:
0
发表于 2011-07-21 09:59 |显示全部楼层
按照网上搜到的资料如下:
http://vim.1045645.n5.nabble.com ... onal-td1141787.html

在.vimrc文件中添加一些配置语句, 要判断vim打开的文件是否是c文件, 语句如下:
  1. let mytype = &filetype
  2. echo "xxxxxxxxxxxxxxxxxxxxxxxxx============="mytype"========================================"
  3. if &filetype=="c" || &filetype=="C"
  4. "if &ft == "c"
  5.     echo "-----------------------file type was c------------------------------"
  6.     " 'filetype' is c
  7. elseif &filetype == "cpp"
  8.     echo "-----------------------file type was cpp------------------------------"
  9.     " it is cpp
  10. else
  11.     echo "-----------------------file type was other------------------------------"
  12.     " it is something else
  13. endif
复制代码
可无论我每次用vim打开什么文件, filetype读取出来都是空的,  输出如下:
  1. $ vi test.c
  2. xxxxxxxxxxxxxxxxxxxxxxxxx=============  ========================================
  3. -----------------------file type was other------------------------------
  4. 请按 ENTER 或其它命令继续
复制代码
而进入了test.c文件后, 我用命令获取到的文件类型又是正确的, 输出如下:
  1. :set filetype
  2. filetype=c
复制代码
请高手解惑

论坛徽章:
0
发表于 2011-07-21 10:06 |显示全部楼层
au FileType C 吧

论坛徽章:
0
发表于 2011-07-21 10:13 |显示全部楼层
filetype on

论坛徽章:
0
发表于 2011-07-21 10:51 |显示全部楼层
学习

论坛徽章:
0
发表于 2011-07-21 11:46 |显示全部楼层
au FileType C 吧
yangyang1581 发表于 2011-07-21 10:06


完全木有用:
  1. filetype on
  2. au FileType C
  3. let mytype = &filetype
  4. echo "xxxxxxxxxxxxxxxxxxxxxxxxx============="mytype"========================================"
  5. if &filetype=="c" || &filetype=="C"
  6. "if &ft == "c"
  7.     echo "-----------------------file type was c------------------------------"
  8.     " 'filetype' is c
  9. elseif &filetype == "cpp"
  10.     echo "-----------------------file type was cpp------------------------------"
  11.     " it is cpp
  12. else
  13.     echo "-----------------------file type was other------------------------------"
  14.     " it is something else
  15. endif
复制代码
设置了以后输出还是:
$ vi test.c

--- 自动命令 ---
xxxxxxxxxxxxxxxxxxxxxxxxx=============  ========================================
-----------------------file type was other------------------------------
请按 ENTER 或其它命令继续

论坛徽章:
0
发表于 2011-07-21 11:48 |显示全部楼层
回复 3# lkk2003rty


这个我也早试过了, 没有用, 进入到c文件以后用filetype看很正常:
  1. :filetype
  2. filetype detection:ON  plugin:ON  indent:ON
复制代码

论坛徽章:
0
发表于 2011-07-21 11:59 |显示全部楼层
au FileType php call AddPHPFuncList()
function AddPHPFuncList()
    echo "-----------------------file type was PHP------------------------------"
endfu

论坛徽章:
0
发表于 2011-07-21 17:49 |显示全部楼层
au FileType php call AddPHPFuncList()
function AddPHPFuncList()
    echo "-----------------------f ...
yangyang1581 发表于 2011-07-21 11:59



    这种方法没有问题, 我以前也是用 autocmd FileType c,cpp 来处理,  偶然在网上发现&filetype的方法, 想尝试下, 结果不行.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP