vimrc 配置中filetype不生效
Tofloor
poster avatar
lnhxzwb
deepin
2019-06-21 19:46
Author
本帖最后由 lnhxzwb 于 2019-6-21 13:13 编辑
  1. cat .vimrc
Copy the Code
  1. cat /etc/vim/vimrc
  2. syntax on
  3. if has("autocmd")
  4.   au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("[        DISCUZ_CODE_1        ]quot;) | exe "normal! g'\"" | endif
  5. endif
  6. filetype on
  7. filetype plugin on

  8. if has("autocmd")
  9.   filetype plugin indent on
  10. endif
Copy the Code

filetype 没有生效,不知道什么情况,有没有知道问题的人
Reply Favorite View the author
All Replies
avatar
liwl
deepin
2019-06-21 19:59
#1
退出终端,重新开启,试过吗?我修改过 ,可以生效
Reply View the author
avatar
Feng Yu
deepin
2019-06-21 20:07
#2
你这个文件的扩展名不是.py吧?
Reply View the author
avatar
lnhxzwb
deepin
2019-06-21 21:05
#3
https://bbs.deepin.org/post/179625
退出终端,重新开启,试过吗?我修改过 ,可以生效

一样,我都重启系统了,还是不能识别
Reply View the author
avatar
lnhxzwb
deepin
2019-06-21 21:07
#4
https://bbs.deepin.org/post/179625
你这个文件的扩展名不是.py吧?

不是,是.sh ,正因为这样才很奇怪,明明filetype都打开了, 就是不能识别
Reply View the author
avatar
lnhxzwb
deepin
2019-06-21 21:10
#5
本帖最后由 lnhxzwb 于 2019-6-21 13:13 编辑
  1. cat .vimrc
  2. autocmd BufNewFile *.sh,*.py exec ":call SetTitle()"  
  3. let $author_name = "xunyin"  
  4. let $author_email = "lnhxzwb@126.com"  


  5. func SetTitle()  
  6. if &filetype == 'sh'  
  7. call setline(1,"\###################################################################")  
  8. call append(line("."), "\# File Name: ".expand("%"))            
  9. call append(line(".")+1, "\# Author: ".$author_name )  
  10. call append(line(".")+2, "\# E-mail: ".$author_email)  
  11. call append(line(".")+3, "\# Created Time: ".strftime("%c"))  
  12. call append(line(".")+4, "\#==================================================================")  

  13. call append(line(".")+5, "\#!/bin/bash")  
  14. call append(line(".")+6, "")  
  15. else

  16. call setline(1,"\###################################################################")  
  17. call append(line("."), "\# File Name: ".expand("%"))  
  18. call append(line(".")+1, "\# Author: ".$author_name)  
  19. call append(line(".")+2, "\# mail: ".$author_email)  
  20. call append(line(".")+3, "\# Created Time: ".strftime("%c"))  
  21. call append(line(".")+4, "\#=============================================================")  

  22. call append(line(".")+5, "\#!/usr/bin/python")  
  23. call append(line(".")+6, "")
  24. endif  
  25. endfunc

  26. autocmd BufNewfile * normal G  
Copy the Code
Reply View the author
avatar
Feng Yu
deepin
2019-06-21 22:33
#6
我知道了,She-bang放那里没用的。she-bang必须放第一行,否则就不是合法的she-bang。你试试把she-bang放第一行再看看
Reply View the author
avatar
158******08
deepin
2019-06-21 22:50
#7
本帖最后由 ptlin 于 2019-6-21 14:53 编辑

这种方法极其不灵活,推荐使用UltiSnips这种snippet插件,你可以参考这篇博客。
Reply View the author