Is there a way to auto add a header when i open a new file in vim?
My objective 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, no header should be inserted.
Type "gg" in command mode. This brings the cursor to the first line.
Just add the "--extra=+f" option in the ctags line. You may then open new files manually with autocompletion, with :tag myfile. cpp Or you may adapt a script like a. vim or FSwitch.
Add this line in your configuration file:
autocmd BufNewFile *.py 0put =\"#!/usr/bin/python\<nl>\"|$
This might be over-kill, but you could look at one of the snippet scripts for Vim, e.g. snipMate -- http://www.vim.org/scripts/script.php?script_id=2540
But, for what you want, you might just map a key to a command that reads in a file. For example:
nmap <leader>r :r boiler_mashbang<cr>
And, then put your boilerplate in the file: boiler_mashbang.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With