gpt4 book ai didi

vim - 给定文件扩展名,如何在vim中定义默认初始文件?

转载 作者:行者123 更新时间:2023-12-05 00:13:08 24 4
gpt4 key购买 nike

每次我写一个新的 python 程序时,我发现自己一遍又一遍地写相同的初始行:

#!/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)

我不想每次都手动完成。每次打开扩展名为 .py 的不存在的文件时,我都希望 vim 向我显示此文件,以便我可以根据需要修改它,然后将其保存到我新创建的源文件中。

我怎样才能做到这一点?

如果答案已经在某处,请道歉。我以为会是,但我在任何地方都找不到。

最佳答案

/etc/vim/vimrc/etc/vimrc~/.vimrc

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

骨架文件:
~/.vim/skeleton.py

将原始帖子中的 python 代码作为 simple-user 放入此文件中

Vim 文档:

skeleton / template autocmd.txt

关于vim - 给定文件扩展名,如何在vim中定义默认初始文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49012031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com