How to determine the default start file in vim given the file extension?

Every time I write a new python program, I find the same starting lines again and again:

#!/usr/bin/env python
'''
Description of the program
'''
import always, the, same, libraries

def helper_function(helpers_args):
'''
A function that is called in get_main_output, but that someone might want to import too.
'''
    continue

def get_main_output(program_arguments):
'''
Description of the main function
'''
    continue

if __name__ == '__main__':
    output = get_main_output(sys.argv)

I do not want to do this manually every time. I would like vim to show me this file every time I open a nonexistent file with the extension .py, so I can modify it as needed, and then save it in the newly created source file.

How can i achieve this?

Apologizes if the answer is already somewhere. I thought it would be, but I could not find it anywhere.

+4
source share
1 answer

In /etc/vim/vimrcor /etc/vimrcor~/.vimrc

" python skeleton
autocmd BufNewFile *.py 0r ~/.vim/skeleton.py

skeleton file:

~/.vim/skeleton.py

Put the python code from your source message inside this file as a simple custom

Vim Documentation:

skeleton/template in autocmd.txt

+6
source

Source: https://habr.com/ru/post/1694186/


All Articles