Skip to content

Instantly share code, notes, and snippets.

@daerich
Last active August 6, 2021 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daerich/0eeb70d5c55c88d6fe58d4408fa22cc3 to your computer and use it in GitHub Desktop.
Save daerich/0eeb70d5c55c88d6fe58d4408fa22cc3 to your computer and use it in GitHub Desktop.
Vim RunCommands
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