-
Notifications
You must be signed in to change notification settings - Fork 1
/
filetype.vim
executable file
·138 lines (115 loc) · 4.39 KB
/
filetype.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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Maintainer :- vallabhdas kansagara<vrkansagara@gmail.com> — @vrkansagara "
" Note :-
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" This file will be loaded by vim by default
" Ref: - https://github.com/vim/vim/blob/master/runtime/filetype.vim
" If vim not detect file type user can add it manually
" Vim script
" Listen very carefully, I will say this only once
if exists("did_load_filetypes")
echoerr "Filetypes does not exists with this vim"
finish
endif
" let did_load_filetypes = 1
" Prevent a file from being sourced multiple times; users can set the variable
" in their configuration to prevent the plugin from loading at all.
if exists('g:loaded_my_plugin')
finish
endif
let g:loaded_my_plugin = v:true
augroup filetypedetect
au! BufRead,BufNewFile *.foo,*.bar,*.baz setfiletype fooBarBaz
au! BufRead,BufNewFile nginx.conf setfiletype nginx
au! BufRead,BufNewFile *.confini *.conf setfiletype conf
augroup END
" :autocmd FileType vim autocmd BufWritePost <buffer> call OnFileSave()
" Pre = onLoad , Post = afterSave
" autocmd BufWritePre <buffer> :call OnFileSave()
autocmd BufWritePost <buffer> :call OnFileSave()
function! OnFileSave()
let ext = &filetype
let file_name = expand('%:t:r')
let extension = expand('%:e')
" Remove last word of each line ( %s/\s*\w\+\s*$// )
" Remove last character of each line ( %s/.\{1}$// )
if ext == 'vim'
" Remove : from every first line
silent! %s/^\s*://
" silent! %s/^map/nnoremap/
" silent! %s/^imap/inoremap/
"nmap <-> nnoremap make issue with coc-nvim , so disable it
" silent! %s/^nmap/nnoremap/
" silent! %s/^cmap/cnoremap/
elseif extension == 'php'
" exe "normal \<F5>"
" Remove closing tag(?>) from every *.php file only TODO
" PHP Performance (insted of " use ')
" silent! %s/\"\([^"]*\)\"/'\1'/g
" silent! %s/\s\+$//g
" silent! call PhpSortUse()
" silent! call PhpCsFixerFixFile()
endif
" Remove white space from all file type
silent! %s/\s\+$//e
endfunction
" How to pipe vim buffer contents via shell command and write output to split
" window
command! FW call FilterToNewWindow('myscript')
function! FilterToNewWindow(script)
let TempFile = tempname()
let SaveModified = &modified
exe 'w ' . TempFile
let &modified = SaveModified
exe 'split ' . TempFile
exe '%! ' . a:script
endfunction
" You can refresh filetype buffer as own your own.
nnoremap <F5> :! echo -e'\033[0m' <CR>:call CallLanguageSpecifiF5()<CR>
function! CallLanguageSpecifiF5()
" (1) To reindent many files, the argument list can be used:
" :args *.c
" :argdo normal gg=G
" :wall
"
"(2) Or use the buffer list (caution, every buffer will be affected):
":bufdo normal gg=G
" :wall
" (3) How to open files with pattern recursively in vim and execute one
" command
" :args /yourfolder/myfile*
" :args /yourfolder/**/myfile*
" :args /yourfolder/**/*.c
" :argdo tabe " Open all marked files into tabs
" :argdo normal gg=G`` " vim style indent all files
" :wall " write all modified files
let ext = &filetype " php, conf
let file_name = expand('%:t:r')
let extension = expand('%:e') " php,phtml,php5,h, vim, c ,cpp, js
" This is dynamic function for all the file type.
" i.e. (1) filetype php , function name = RefreshF5php()
" i.e. (2) filetype vim, function name = RefreshF5vim()
let function_name = "RefreshF5" . ext
if exists("*". function_name)
exe "call " . function_name ."()"
else
echoerr function_name 'does not exitsts'
endif
" Remove white space from all file type
silent! %s/\s\+$//e
endfunction
autocmd FileType * noremap <C-m> :call ExecuteCurrentFile()<cr>
function! ExecuteCurrentFile()
let ext = &filetype " php, conf
let file_name = expand('%:t:r')
let extension = expand('%:e') " php,phtml,php5,h, vim, c ,cpp, js
" This is dynamic function for all the file type.
" i.e. (1) filetype php , function name = Runphp()
" i.e. (2) filetype vim, function name = Runvim()
let function_name = "Run" . ext
if exists("*". function_name)
exe "call " . function_name ."()"
else
echoerr function_name 'does not exitsts'
endif
endfunction