How can I automatically add some skeleton code when creating a new file with vim

后端 未结 8 1422
清歌不尽
清歌不尽 2020-11-29 02:42

When creating a new file with vim, I would like to automatically add some skeleton code.

For example, when creating a new xml file, I would like to add the first lin

8条回答
  •  清酒与你
    2020-11-29 03:07

    Here are two examples using python scripting.

    Add something like this in your .vimrc or another file sourced by your .vimrc:

    augroup Xml
      au BufNewFile *.xml :python import vim
      au BufNewFile *.xml :python vim.current.buffer[0:0] = ['']
      au BufNewFile *.xml :python del vim
    augroup END
    
    fu s:InsertHtmlSkeleton()
      python import vim
      python vim.current.buffer[0:0] = ['', "", "", "  ", "", "", "", "", ""]
      python del vim
    endfu
    
    augroup Html
      au BufNewFile *.html call InsertHtmlSkeleton()
    augroup END
    

提交回复
热议问题