挑战“VimGolf的简单文本编辑”VimGolf:#1解决方案如何工作?
使用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 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命令显然会删除该行。它被给了一个范围 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
我没有提到的一件事是为什么:g命令执行三次,而不是6次甚至更多次(行沿着进程重复)。 :g命令开始将光标定位在第一行,并转到$。但如果命令更改当前行,则:g从那里继续。所以: :G/V/ 当前行是4.现在: t. 这将光标移动到第5行。然后: +d 删除第6行,光标保留在5.所以下一个:g匹配将在第8行。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |