search

Home  >  Q&A  >  body text

javascript - How to automatically add "use strict" when creating a new js file?

setline(1,"\"use strict\"")No.

伊谢尔伦伊谢尔伦2753 days ago802

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-06-06 09:56:23

    Use the automated build tool gulp to write ES6 directly after configuration

    reply
    0
  • 滿天的星座

    滿天的星座2017-06-06 09:56:23

    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()"
    

    This is convenient for adding similar functions to other types of files in the future. See Vim to automatically add file headers when creating new files

    Or just for this usage scenario:

    function! s:add_title_js()
        call setline(1,'use strict')
        call append(line('.'), '')
    endfunction
    
    autocmd FileType javascript execute "call s:add_title_js()"
    

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-06 09:56:23

    What editor are you using?

    reply
    0
  • Cancelreply