Last active
August 6, 2021 20:33
-
-
Save daerich/0eeb70d5c55c88d6fe58d4408fa22cc3 to your computer and use it in GitHub Desktop.
Vim RunCommands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source $VIMRUNTIME/defaults.vim | |
:function PythonEnt(isnf,lang) | |
:let l:filen = expand("%:p") | |
:if a:lang == "Py" | |
:if len(glob("*.py",0,1)) <= 1 && !a:isnf | |
\&& filewritable(filen) | |
\&& getfsize(filen) == 0 | |
:call setline(1,"#!/usr/bin/env python") | |
:elseif empty(glob("*.py",0,1)) && a:isnf | |
:call setline(1,"#!/usr/bin/env python") | |
:endif | |
:endif | |
:if a:lang == "C" | |
:if len(glob("*.c",0,1)) <= 1 && !a:isnf | |
\&& filewritable(filen) | |
\&& getfsize(filen) == 0 | |
:call append(0,['#include <stdio.h>','#include <stdlib.h>', | |
\"", | |
\ "int main(int argc,char** argv)", | |
\"{","\treturn 0;","}"]) | |
:elseif empty(glob("*.c",0,1)) && a:isnf | |
:call append(0,['#include <stdio.h>','#include <stdlib.h>', | |
\"", | |
\ "int main(int argc,char** argv)", | |
\"{","\treturn 0;","}"]) | |
:endif | |
:endif | |
:endfunction | |
:autocmd BufNewFile *.py call PythonEnt(1,"Py") | |
:autocmd BufReadPost *.py call PythonEnt(0,"Py") | |
:autocmd BufNewFile *.c call PythonEnt(1,"C") | |
:autocmd BufReadPost *.c call PythonEnt(0,"C") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment