-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmin.vim
More file actions
32 lines (32 loc) · 857 Bytes
/
min.vim
File metadata and controls
32 lines (32 loc) · 857 Bytes
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
" ======================================================================
" File: min.vim
" Author: zyprex
" Description: minify html css js, save 20% size
" Usage: execute command ':so min.vim'
" Last Modified: January 14, 2021
" ======================================================================
"#1 remove space wrap around sentence
%s/\(^\s\+\|\s\+$\)/
"#2 clear /*...*/
while (1)
try
/^\s*\/\*/,/^\s*\*\//s/.*
catch /^Vim\%((\a\+)\)\=:E/ "all vim error
echo v:exception
break
endtry
endwhile
"#3 clear //...
%s/^\/\/.*/
"#4 remove space between symbol
"%s/\s*\(&&\|||\|%\|?\|!\|:\|=\|+\|,\|;\|}\|{\|)\|(\|\]\|\[\)\s*/\1/
%s/" "/SPACESTRINGRP1/
%s/" "/SPACESTRINGRP2/
%s/\s*\(\W\)\s*/\1/
"#4.1 special case
%s/SPACESTRINGRP1/" "/
%s/SPACESTRINGRP2/" "/
%s/\(#s\|#l\|#eph\|body\)\*/\1 \*/
%s/and(/and (/
"#5 remove linefeed
%s/\n/