Vim 中有自动缩小 CSS、Html 和 Javascript 代码的方法或插件吗?

发布于 2024-09-06 12:30:09 字数 1718 浏览 8 评论 0原文

我想知道是否有一种方法可以自动缩小 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绝不放开 2024-09-13 12:30:09

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.

最丧也最甜 2024-09-13 12:30:09

有一个名为 vim-minify 的插件,它的工作原理是:

.. 来自 javascript-minifier.com 和 cssminifier.com 的 API,作者:Andrew Chilton。


在 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:

.. the API from javascript-minifier.com and cssminifier.com by Andrew Chilton.


In JavaScript

  • :MinifyJS minifies your javascript code to filename.min.js
  • :UnMinifyJS reformat to be human readable

In CSS files

  • :MinifyCSS minifies your css code to filename.min.css
  • :UnMinifyCSS reformat to be human readable
绳情 2024-09-13 12:30:09

进入可视模式选择整个文件并按SHIFT-J

Enter visual mode select whole file and press SHIFT-J.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文