javascript - 新建js文件时如何自动地加上"use strict"?
伊谢尔伦
伊谢尔伦 2017-06-06 09:54:23
0
3
753

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

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(3)
大家讲道理

使用自动化构建工具 gulp 配置好后可以直接写 ES6

滿天的星座
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()"
曾经蜡笔没有小新

用的什么编辑器?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!