Vim 中有自动缩小 CSS、Html 和 Javascript 代码的方法或插件吗?
我想知道是否有一种方法可以自动缩小 html、css 或 javascript 文件。 这样每次我保存“源文件”时,Vim 都会自动对文件的缩小版本进行相同的更改(或者自动创建或覆盖缩小版本)。 类似这样的内容:
来源:
// The -is- object is used to identify the browser. Every browser edition
// identifies itself, but there is no standard way of doing it, and some of
// the identification is deceptive. This is because the authors of web
// browsers are liars. For example, Microsoft's IE browsers claim to be
// Mozilla 4. Netscape 6 claims to be version 5.
var is = {
ie: navigator.appName == 'Microsoft Internet Explorer',
java: navigator.javaEnabled(),
ns: navigator.appName == 'Netscape',
ua: navigator.userAgent.toLowerCase(),
version: parseFloat(navigator.appVersion.substr(21)) ||
parseFloat(navigator.appVersion),
win: navigator.platform == 'Win32'
}
is.mac = is.ua.indexOf('mac') >= 0;
if (is.ua.indexOf('opera') >= 0) {
is.ie = is.ns = false;
is.opera = true;
}
if (is.ua.indexOf('gecko') >= 0) {
is.ie = is.ns = false;
is.gecko = true;
}
缩小版:
var is={ie:navigator.appName=='Microsoft Internet Explorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'}
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}
I would like to know if there's a way of automatically minify html, css or javascript files.
So that each time I save the "source file" Vim automatically make the same changes to a minified version of the file (or automatically creates or override a minified version). Something like this:
Source:
// The -is- object is used to identify the browser. Every browser edition
// identifies itself, but there is no standard way of doing it, and some of
// the identification is deceptive. This is because the authors of web
// browsers are liars. For example, Microsoft's IE browsers claim to be
// Mozilla 4. Netscape 6 claims to be version 5.
var is = {
ie: navigator.appName == 'Microsoft Internet Explorer',
java: navigator.javaEnabled(),
ns: navigator.appName == 'Netscape',
ua: navigator.userAgent.toLowerCase(),
version: parseFloat(navigator.appVersion.substr(21)) ||
parseFloat(navigator.appVersion),
win: navigator.platform == 'Win32'
}
is.mac = is.ua.indexOf('mac') >= 0;
if (is.ua.indexOf('opera') >= 0) {
is.ie = is.ns = false;
is.opera = true;
}
if (is.ua.indexOf('gecko') >= 0) {
is.ie = is.ns = false;
is.gecko = true;
}
Minified Version:
var is={ie:navigator.appName=='Microsoft Internet Explorer',java:navigator.javaEnabled(),ns:navigator.appName=='Netscape',ua:navigator.userAgent.toLowerCase(),version:parseFloat(navigator.appVersion.substr(21))||parseFloat(navigator.appVersion),win:navigator.platform=='Win32'}
is.mac=is.ua.indexOf('mac')>=0;if(is.ua.indexOf('opera')>=0){is.ie=is.ns=false;is.opera=true;}
if(is.ua.indexOf('gecko')>=0){is.ie=is.ns=false;is.gecko=true;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这不是 VIM,而是 http://code.google.com/p/minify/< /a> Minify 项目在互联网上实时压缩它们,因此您不必担心源文件被意外压缩得无法识别。
I know it's not VIM, but the http://code.google.com/p/minify/ Minify project live compresses them on the internet, so you don't have to worry about your source files becoming compressed beyond recognition accidentally.
有一个名为 vim-minify 的插件,它的工作原理是:
在 JavaScript 中
:MinifyJS
将 JavaScript 代码缩小为 filename.min.js:UnMinifyJS
重新格式化为人类可读< em>在 CSS 文件中
:MinifyCSS
将 CSS 代码缩小为 filename.min.css:UnMinifyCSS
重新格式化为人类可读的格式There is a plugin called vim-minify which works by using:
In JavaScript
:MinifyJS
minifies your javascript code to filename.min.js:UnMinifyJS
reformat to be human readableIn CSS files
:MinifyCSS
minifies your css code to filename.min.css:UnMinifyCSS
reformat to be human readable进入可视模式选择整个文件并按
SHIFT-J
。Enter visual mode select whole file and press
SHIFT-J
.