javascript - 新建js文件时如何自动地加上"use strict"?

查看:156
本文介绍了javascript - 新建js文件时如何自动地加上"use strict"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

setline(1,"\"use strict\"")不行。

解决方案

function! s:add_title()
  if &filetype == 'javascript'
    call setline(1, 'use strict')
    call append(line('.'), '')
  endif
endfunction

autocmd BufNewFile *.js execute "call s:add_title()"

这个方便以后为其他类型的文件添加相似的功能, 参见 Vim 新建文件时自动添加文件头

或者仅针对这个使用场景:

function! s:add_title_js()
    call setline(1,'use strict')
    call append(line('.'), '')
endfunction

autocmd FileType javascript execute "call s:add_title_js()"

这篇关于javascript - 新建js文件时如何自动地加上"use strict"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆