DZ小明 2017-04-04 12:59 采纳率: 75%
浏览 1698
已采纳

为什么我的vim进入后没有使用SetTitle函数?

  我的settitle是这样写的,但是创建一个C文件,vim进入后,并没有添加作者信息和头文件,这时为什么呢?

 "新建.c,.h,.sh,.java文件,自动插入文件头 
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()" 
""定义函数SetTitle,自动插入文件头 
func SetTitle() 
"如果文件类型为.sh文件 
if &filetype == 'sh' 
call setline(1,"\#!/bin/bash") 
call append(line("."), "") 
elseif &filetype == 'python'
call setline(1,"#!/usr/bin/env python")
call append(line("."),"# coding=utf-8")
call append(line(".")+1, "") 

elseif &filetype == 'ruby'
call setline(1,"#!/usr/bin/env ruby")
call append(line("."),"# encoding: utf-8")
call append(line(".")+1, "")

" elseif &filetype == 'mkd'
" call setline(1,"<head><meta charset=\"UTF-8\"></head>")
else 
call setline(1, "/*************************************************************************") 
call append(line("."), "    > File Name: ".expand("%")) 
call append(line(".")+1, "  > Author: ") 
call append(line(".")+2, "  > Mail: ") 
call append(line(".")+3, "  > Created Time: ".strftime("%c")) 
call append(line(".")+4, " ************************************************************************/") 
call append(line(".")+5, "")
endif
if expand("%:e") == 'cpp'
call append(line(".")+6, "#include<iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "")
endif
if expand("%:e") == 'h'
call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
call append(line(".")+8, "#endif")
endif
if &filetype == 'java'
call append(line(".")+6,"public class ".expand("%:r"))
call append(line(".")+7,"")
endif
"新建文件后,自动定位到文件末尾
endfunc

  • 写回答

1条回答

  • devmiao 2017-04-04 15:24
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝