Auto insert header in vim

Is there a way to automatically add a title when I open a new file in vim? My goal is to automatically add the shebang "#! /usr/bin/python" when I open a new file using the command "vim test.py" . If the file is already present, the header should not be inserted.

+8
python command-line vim
source share
2 answers

Add this line to your configuration file:

 autocmd BufNewFile *.py 0put =\"#!/usr/bin/python\<nl>\"|$ 
+24
source share

This may be excessive, but you can look at one of the fragment scripts for Vim, for example. snipMate - http://www.vim.org/scripts/script.php?script_id=2540

But for what you want, you can simply map the key to the command that is read in the file. For example:

 nmap <leader>r :r boiler_mashbang<cr> 

And then paste your template into the file: boiler_mashbang.

+3
source share

All Articles