加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

挑战“VimGolf的简单文本编辑”VimGolf:#1解决方案如何工作?

发布时间:2020-12-15 19:16:06 所属栏目:安全 来源:网络整理
导读:使用Vim进行简单的文字编辑: http://vimgolf.com/challenges/4d1a34ccfa85f32065000004 我发现很难理解#1解决方案(得分13)。 对不起,这篇文章中没有粘贴任何解决方案,因为我不知道这样做是否合适。 解决方案集中在:g命令。从帮助: :g :global E147 E148
使用Vim进行简单的文字编辑:
http://vimgolf.com/challenges/4d1a34ccfa85f32065000004

我发现很难理解#1解决方案(得分13)。

对不起,这篇文章中没有粘贴任何解决方案,因为我不知道这样做是否合适。

解决方案集中在:g命令。从帮助:
:g   :global   E147   E148 
:[range]g[lobal]/{pattern}/[cmd]
                        Execute the Ex command [cmd] (default ":p") on the
                        lines within [range] where {pattern} matches.

所以基本上,解决方案在具有“V”的行上执行一些ex命令,
这正是需要编辑的。你可能注意到了
早期的解决方案依赖于复制线,而不是真正改变
他们。该解决方案特别显示了一个有趣的模式:

3jYjVp3jYjVp3jYjVpZZ
^     ^     ^

宏可以减少哪些:

qa3jYjVpq3@aZZ

使用:g命令的解决方案基本上是一样的。首先
命令执行是t ..从帮助:

:t 
:t                  Synonym for copy.

:[range]co[py] {address}                             :co   :copy 
                        Copy the lines given by [range] to below the line
                        given by {address}.

给出的地址是。,这意味着当前行:

Line numbers may be specified with:          :range   E14   {address} 
        {number}            an absolute line number
        .                   the current line                           :. 
        $                   the last line in the file                  :$ 
        %                   equal to 1,$ (the entire file)             :% 
        't                  position of mark t (lowercase)             :' 
        'T                  position of mark T (uppercase); when the mark is in
                            another file it cannot be used in a range
        /{pattern}[/]       the next line where {pattern} matches      :/ 
        ?{pattern}[?]       the previous line where {pattern} matches  :? 
        /                  the next line where the previously used search
                            pattern matches
        ?                  the previous line where the previously used search
                            pattern matches
        &;                  the next line where the previously used substitute
                            pattern matches

所以ex命令t。表示“将当前行复制到当前行以下”。
然后,有一个酒吧:

:bar   :bar 
'|' can be used to separate commands,so you can give multiple commands in one
line.  If you want to use '|' in an argument,precede it with ''.

而d命令显然会删除该行。它被给了一个范围
,意为“当前行1”。你可以通过1但简而言之
这些信息可以阅读周围的帮助:范围:

The default line specifier for most commands is the cursor position,but the
commands ":write" and ":global" have the whole file (1,$) as default.

Each may be followed (several times) by '+' or '-' and an optional number.
This number is added or subtracted from the preceding line number.  If the
number is omitted,1 is used.

就是这样

:G/V/t.|+d<CR>ZZ

On every line that has a “V”,copy it down and delete the next line. Write
and quit.

我没有提到的一件事是为什么:g命令执行三次,而不是6次甚至更多次(行沿着进程重复)。 :g命令开始将光标定位在第一行,并转到$。但如果命令更改当前行,则:g从那里继续。所以:

:G/V/

当前行是4.现在:

t.

这将光标移动到第5行。然后:

+d

删除第6行,光标保留在5.所以下一个:g匹配将在第8行。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读