手を動かしながら vim-surround の使い方を覚える.
概要は次の通り.
動作環境
- mac mojave 10.14.5
- vim 8.0
vim-plug で plugin 管理.
これについては過去の記事参照.
前提条件
plugin inst. 方法や plugin についての詳細は省略.
github を斜め読みするところからスタート.
あと cs
を change surroundings
って書いてるけど, help を参照してこの略称だろうなって感じでまとめる.
好みの問題なので適宜読み替えて.
ヘルプ表示
github には書いてないけど次のコマンドでヘルプが見れる.
:help surround
見ているものはリポジトリ内のこれだったりする.
- https://github.com/tpope/vim-surround/blob/master/doc/surround.txt
cs (change surroundings)
心の中で change surroundings before after って唱えながらコマンドを叩く.
cs"'
# before
"This is my blog !"
# after
'This is my blog !'
cs'<li>
# before
'This is my blog !'
# after
<li>This is my blog !</li>
cst'
- 心の中で change surroundings tags (to) after って唱える
# before
<li>This is my blog !</li>
# after
'This is my blog !'
ds (delete surroundings)
心の中で delete surroundings コレ って唱えながらコマンドを叩く.
ds'
# before
'This is my blog !'
# after
This is my blog !
dst
- 心の中で delete surroundings tags って唱える
# before
<div>This is my blog !</div>
# after
This is my blog !
ysiw (you surround iw)
これは motion や text object っぽい動きだね.
help から you surround
って読み解いたけど, 個人的にはこっちの方が心の中で唱えやすい.
yield surroundings inside (a/the) word
そんな感じでコマンドを叩いてみる.
*
がカーソルの位置.
ysiw]
- 心の中で yield surroundings inside (a/the) word って唱える
- スペース ナシの括弧
# before
This is my b*log !
# after
This is my [blog] !
ysiw[
- 心の中で yield surroundings inside (a/the) word って唱える
- スペース アリの括弧
# before
This is my b*log !
# after
This is my [ blog ] !
yss (you surround special)
個人的には yield surroundings special がいいな.
単語間の空白を無視して surround してくれるあたりが special っぽい.
yss)
- 心の中で yield surroundings supecial コレ って唱える
# before
This is my blog !
# after
(This is my blog !)
S
ここまで呪文を唱えてきたけど visual mode で S
(ラージ s) を使えばもっと簡単.
- if の
()
を付与 - foo…, baa… を html リストへ
<?php
if $a === 'fooo' {
echo "is fooo. \n";
}
?>
fooooooooo
baaaaaaaaaa
まとめ
慣れるまで少し時間がかかるかも.
今回は以上.