LoginSignup
0
0

More than 5 years have passed since last update.

VimGolf 解説 Space out the alphabet

Last updated at Posted at 2017-10-28

解説する問題はこれ: https://www.vimgolf.com/challenges/56fb2e75ccffcc0009026473
興味ある方は是非、下の解説を見ずに挑戦してみてください。

start
abcde
fghij
klmno
pqrst
uvwxyz
goal
a   b   c   d   e
f   g   h   i   j
k   l   m   n   o
p   q   r   s   t
u   v   w   x   y   z

以下解説


解答(現状最短解)

15 ストローク
<:%s/./ &/g<CR>.ZZ

解説

この15文字に詰まっているテクニックを解説する。

:%s/./ &/g

:s 置換: [range]s[ubstitute]/{pattern}/{string}/[flags] [count]
* %: すべての行
* .: 任意の一文字
* &: ヒットした pattern 全部 \0 と同じ
* g: 行内すべて

この時点

a b c d e
f g h i j 
k l m n o
p q r s t
u v w x y z

<:%s

<{motion} : {motion} 行を 'shiftwidth' 1個分左にずらす。
<:%: すべての行に command line mode 実行し、最後に対象行を 1個分左にずらす。

ここがポイントで <{motion} を使っているためこの後 command line mode の実行を single-repeat できる

.

single-repeat する。前述のとおり。

ZZ

保存して終了。

終わり

他の問題を解説したものも紹介しておきます。
https://qiita.com/elzup/items/5b6992d21408ba35a3b4

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0