zoukankan      html  css  js  c++  java
  • VIM

    1. 概述

      1. vim 运行 ex 脚本
    2. 背景

      1. 最近在整理一些文本资料
      2. 发现有某个网站上资料质量还行
        1. 就是妈的禁用了各种操作
          1. 鼠标左键选取
          2. 鼠标右键菜单
          3. 键盘快捷键
      3. 尝试从 js 的角度改变, 结果失败
        1. 这个时候知道前端知识的重要性了?
      4. 无奈只能尝试通过 文本处理 的方式来处理
        1. 暂时使用 vim
          1. 其实 sed 也可以
        2. 需要连续的几个 ex 命令
    3. 环境

      1. OS
        1. win10
      2. shell
        1. mintty-2.9.4
    4. 准备

      1. 原始文本

        # demo.html
        <p>TUTOR: Right, Jason and Karin, now I asked you to look at the case study for Box Telecom as part of your exam assessment. It’s interesting because they are in the middle of problems at the moment and I want you to track how they deal with them. Let’s start with you, Karin. Having read through the case study, can you just summarise what the problems were that Box Telecom had to take on board?</p>
        <p>KARIN: Um, yeah… Well of course what first came to their attention was that, despite a new advertising campaign, they were suffering from falling <span style="color: #ff0000;"><strong>sales </strong></span>– and this is something that had many causes. On top of that immediate problem, what had also happened over the last two years was that, although they had invested in an expansion plan, they had to face up to increased <span style="color: #ff0000;"><strong>competition</strong></span>. And, before they had a chance to get to grips with the effects of that, they were stalled by a strike and it was just when they were thinking about making a colossal investment in new machinery for their plants. So they were really in trouble.&nbsp;&nbsp;&nbsp; <span style="color: #ff0000;"><strong>Q21, Q22</strong></span></p>
        <p>TUTOR: Yes, I think that’s fair. And Jason, you contacted the company, didn’t you?What did the company define as the reasons for these problems?</p>
        <p>JASON: Well, I think they’ve hit on the right things – it would be easy to say they had invested too heavily, or at the wrong time, but in fact the signs were good and what they were set back by was high <span style="color: #ff0000;"><strong>interest rates</strong></span>. At the same time, their longer-term problems, which were affecting their market share, were eventually credited to poor <span style="color: #ff0000;"><strong>training </strong></span>– and having looked at the details in their last report I think that’s right.&nbsp;&nbsp;&nbsp;<span style="color: #ff0000;"><strong> Q23, Q24</strong></span></p>
        <p>TUTOR: So, onto the larger issues then. Karin, what do you think the company will do?</p>
        <p>KARIN: Hmm… Well, obviously they have the choice of accepting the very favourable terms that another company – KMG Plc- have given them to buy them out. That would mean creating a new company with a new image. Or they could decide on a bolder move and offer some new shares if they wanted. But I think they’re much more cautious than that and expect they will start <span style="color: #ff0000;"><strong>trying to find individuals who’d be prepared to back them with some of the capital they need</strong></span>.&nbsp;&nbsp;&nbsp; <span style="color: #ff0000;"><strong>Q25</strong></span></p>
        <p>TUTOR: Well, you mustn’t always assume that dramatic problems require dramatic solutions. Sometimes there’s a simple fix such as changing the guy at the top. If they truly are cautious, then I suspect they will seek to shut down some of their shops. But a more ambitious approach, and one which I think would have more chance of success, would be to <span style="color: #ff0000;"><strong>alter how they’re running things</strong></span> – the management layers and the processes. So in your analysis try to think of all the options. Jason?&nbsp; <span style="color: #ff0000;"><strong>Q26</strong></span></p>
        <p>JASON: Yes, it’s interesting because I’ve found it a really useful company to study. Its problems cross all types of industries and it’s lucky it’s so big – a smaller or even medium-sized company would have gone under by now.</p>
        <p>TUTOR: Ah well in fact, what I want you two to do is to go away when we’ve finished our discussion today and write a report. We’ve looked in general at the telecommunications market in the UK over the last few sessions and I want you to take Box Telecom as an example and <span style="color: #ff0000;"><strong>suggest some ways in which they might overcome their problems</strong></span>. And outline the reasons why you think as you do – but try and keep it intrinsic to the company rather than dragging in other examples. Is that OK, Karin?&nbsp;&nbsp;&nbsp; <span style="color: #ff0000;"><strong>Q27</strong></span></p>
        <p>KARIN: Yes, I think I can do that. Personally I’ve got great hopes for it.<span style="color: #ff0000;"><strong> I think it will recover</strong></span>. That advertising campaign they did was very strong and they’re very innovative with their products – they set new trends. The company’s got to recover, don’t you think, Jason?&nbsp;&nbsp;&nbsp;<span style="color: #ff0000;"><strong> Q28</strong></span></p>
        <p>JASON: Hmmm – I’m not sure. I think it can but it’s not a foregone conclusion unless they manage <span style="color: #ff0000;"><strong>to attract the right level of investment</strong><strong>. The company definitely needs a boost</strong></span> and to attract more highly skilled workers if their recovery is to be long-lasting. When I was talking to the marketing manager he said to me that he thinks the company had got a great management team – but he would say that, wouldn’t he? – but they are suffering from having to work with outdated production machinery and that could cost a lot to put right.&nbsp;&nbsp;&nbsp; <span style="color: #ff0000;"><strong>Q29</strong></span></p>
        <p>TUTOR: Well, personally I think the stock market is to blame. I think they were expecting too much of the company and then inevitably it looked bad when it didn’t perform. The market should have had more realistic expectations. <span style="color: #ff0000;"><strong>And I disagree with you about the advertising campaign Karin. That’s where they could do with some innovation</strong></span> – to get sales kick-started. Anyway, let’s see what you come up with… [fade]&nbsp;&nbsp;<span style="color: #ff0000;"><strong>&nbsp; Q30</strong></span></p>
        
      2. 整理后需要

        1. 去掉  
        2. 去掉 Q2 之类的符号
        3. 去掉所有的 html 标签
      3. 命令

        # 执行前, 需要 : 唤起 ex命令模式
        % s/&nbsp;//g
        % s/<strong>s?Q.*</strong>//g
        % s/<.{-}>//g
        

    1. 思路1: 直接执行

    1. 概述

      1. 直接执行
    2. 操作

      1. 进入文本
      2. 逐条执行命令
      3. 得出结果
    3. 问题

      1. 逐条执行命令
        1. 手打烦
        2. 复制粘贴也烦
      2. 有没有什么办法, 可以像执行脚本那么执行呢
        1. 当然有啦

    2. 思路2: vim 内脚本执行

    1. 概述

      1. vim 内脚本执行
    2. 操作

      1. 整理脚本文件

        # ex.vim, 拓展名其实无所谓
        % s/&nbsp;//g
        % s/<strong>s?Q.*</strong>//g
        % s/<.{-}>//g
        
      2. 用 vim 打开 demo.html

      3. 执行命令

        # 执行前, 需要 : 唤起 ex命令模式
        # 执行前有 确认
        # 执行后如果不满意, 可以直接回退...
        :source ex.vim
        
    3. 结果

      1. 执行成功
      2. 调试方便
        1. 就算执行结果有问题, 可以立即使用 u 来回退
    4. 问题

      1. 如果可以对多个文本执行, 效率会比较高一点

    3. 思路3: vim 内多文件脚本执行

    1. 概述

      1. vim 内多文件脚本执行
    2. 操作

      1. 整理脚本文件

      2. 用 vim 打开多个文档

        > vim demo01.html demo02.html
        
      3. 执行命令

        # 执行前, 需要 : 唤起 ex命令模式
        source ex.vim | w
        
    3. 解释

      1. |

        1. 相当于 ;
        2. 一行执行两条命令
      2. |w

        1. 执行 ex 脚本后, 立即 w
        2. 否则的话, 会因为没有保存, 无法切换窗口

    4. 思路4: 命令行多文件脚本执行

    1. 概述

      1. 命令行多文件执行
    2. 操作

      1. 整理脚本文件

      2. 命令

        > vim -c 'argdo source ex.vim|w' demo01.html demo02.html
        
    3. 结果

      1. 类似 思路3
      2. 而且无法回退

    ps

    1. ref

      1. VIM学习笔记 Ex脚本 (Ex Script)
        1. 这个专栏写的还不错
    2. 后续

      1. ex 脚本

        1. 其实还有很多东西可以讲
        2. 用到了再慢慢学吧
      2. 流编辑器

        1. 编辑相关的 ex 脚本, 其实都可以转化为 sed 脚本
          1. 这个以后一定要做
  • 相关阅读:
    贪心算法 Wooden Sticks
    HDOJ 2189 悼念512汶川大地震遇难同胞——来生一起走
    hdoj1069 Monkey and Banana(最长上升子序列)
    2012级计科《程序设计基础Ⅱ》期末上机考试
    Constructing Roads In JGShining's Kingdom
    c语言学习随笔之指针(二)
    c语言学习随笔之指针(一)
    遍历网页框架结构
    笔记本测试软件(让奸商头疼的软件)0
    ResizePicturevb.net
  • 原文地址:https://www.cnblogs.com/xy14/p/12750485.html
Copyright © 2011-2022 走看看