forked from HelifeWasTaken/vim-epitech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epitech.vim
158 lines (130 loc) · 4.67 KB
/
epitech.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
""
"" EPITECH PROJECT, 2020
"" Vim Epitech
"" File description:
"" A Vim configuration for the Epitech curriculum
""
syntax on
" Numbers on the left
set title
" Show line and column on the bottom right
set ruler
" Identation settings
set tabstop=4
set shiftwidth=4
set expandtab
set ai
set si
" Set unix format for carriage returns
set fileformat=unix
" Considerate a *.h as *.c
autocmd BufNewFile,BufRead *.h set filetype=c
if (&ft == 'c') || (&ft == 'cpp')
setlocal comments=s:/*,m:**,ex:*/
endif
" Epitech Header
let s:comMapNoShebang = {
\ 'c': {'b': '/*', 'm': '**', 'e': '*/'},
\ 'cpp': {'b': '//', 'm': '//', 'e': '//'},
\ 'make': {'b': '##', 'm': '##', 'e': '##'},
\ 'java': {'b': '//', 'm': '//', 'e': '//'},
\ 'latex': {'b': '%%', 'm': '%%', 'e': '%%'},
\ 'html': {'b': '<!--', 'm': ' --', 'e': '-->'},
\ 'lisp': {'b': ';;', 'm': ';;', 'e': ';;'},
\ 'css': {'b': '/*', 'm': '**', 'e': '*/'},
\ 'pov': {'b': '//', 'm': '//', 'e': '//'},
\ 'pascal': {'b': '{ ', 'm': ' ', 'e': '}'},
\ 'haskell': {'b': '{-', 'm': '-- ', 'e': '-}'},
\ 'vim': {'b': '""', 'm': '"" ', 'e': '""'},
\}
let s:comMapShebang = {
\ 'sh': {'s': '#!/usr/bin/env sh', 'b': '##', 'm': '##', 'e': '##'},
\ 'bash': {'s': '#!/usr/bin/env bash', 'b': '##', 'm': '##', 'e': '##'},
\ 'zsh': {'s': '#!/usr/bin/env zsh', 'b': '##', 'm': '##', 'e': '##'},
\ 'php': {'s': '#!/usr/bin/env php', 'b': '/*', 'm': '**', 'e': '*/'},
\ 'perl': {'s': '#!/usr/bin/env perl', 'b': '##', 'm': '##', 'e': '##'},
\ 'python': {'s': '#!/usr/bin/env python3', 'b': '##', 'm': '##', 'e': '##'},
\ 'ruby': {'s': '#!/usr/bin/env ruby', 'b': '##', 'm': '##', 'e': '##'},
\ 'node': {'s': '#!/usr/bin/env node', 'b': '/*', 'm': '**', 'e': '*/'},
\}
function! s:Epiyear()
let old_time = v:lc_time
language time en_US.utf8
let str = strftime("%Y")
exec 'language time '.old_time
return str
endfunction
function! s:InsertFirst()
call inputsave()
let proj_name = input('Enter project name: ')
let file_desc = input('Enter file description: ')
call inputrestore()
1,6s/µPROJECTNAMEµ/\= proj_name/ge
1,6s/µYEARµ/\= s:Epiyear()/ge
1,6s/µFILEDESCµ/\= file_desc/ge
endfunction
function! s:IsSupportedFt()
return has_key(s:comMapNoShebang, &filetype)
endfunction
function! s:IsSupportedFtShebang()
return has_key(s:comMapShebang, &filetype)
endfunction
function! Epi_header()
if s:IsSupportedFt()
let Has_Shebang = 0
elseif s:IsSupportedFtShebang()
let Has_Shebang = 1
else
echoerr "Epitech header: Unsupported filetype: " . &filetype . " If you think this an error or you want an additional filetype please contact me :)"
return
endif
if Has_Shebang == 0
let l:bcom = s:comMapNoShebang[&filetype]['b']
let l:mcom = s:comMapNoShebang[&filetype]['m']
let l:ecom = s:comMapNoShebang[&filetype]['e']
let l:ret = append(0, l:bcom)
let l:ret = append(1, l:mcom . " EPITECH PROJECT, µYEARµ")
let l:ret = append(2, l:mcom . " µPROJECTNAMEµ")
let l:ret = append(3, l:mcom . " File description:")
let l:ret = append(4, l:mcom . " µFILEDESCµ")
let l:ret = append(5, l:ecom)
else
let l:scom = s:comMapShebang[&filetype]['s']
let l:bcom = s:comMapShebang[&filetype]['b']
let l:mcom = s:comMapShebang[&filetype]['m']
let l:ecom = s:comMapShebang[&filetype]['e']
let l:ret = append(0, l:scom)
let l:ret = append(1, l:bcom)
let l:ret = append(2, l:mcom . " EPITECH PROJECT, µYEARµ")
let l:ret = append(3, l:mcom . " µPROJECTNAMEµ")
let l:ret = append(4, l:mcom . " File description:")
let l:ret = append(5, l:mcom . " µFILEDESCµ")
let l:ret = append(6, l:ecom)
endif
call s:InsertFirst()
:8
endfunction
command! EpiHeader call Epi_header()
" Compile command
function! Compile()
let b:ccommand = "make"
echohl Question
let b:ccommand = input("compile : ", b:ccommand)
echohl None
let &makeprg = b:ccommand
exec "make"
endfunction
command! -nargs=0 Compile call Compile()
" Goto line command
function! GotoLine()
let b:gotoline_n = ""
echohl Question
let b:gotoline_n = input("Goto Line : ", b:gotoline_n)
echohl None
exec b:gotoline_n
endfunction
command! -nargs=0 GotoLine call GotoLine()
" Global bindings
nnoremap <C-c><C-h> :EpiHeader<CR>
nnoremap <C-c><C-c> :w <bar> Compile<CR>
nnoremap <C-g> :GotoLine<CR>