LoginSignup
6
8

More than 5 years have passed since last update.

最近めちゃくちゃ便利になった Vim の dot repeat の設定

Posted at

ブログ記事からの転載です。

最近…というか asterisk.vim を使い始めた頃に(いまさら)dot repeat にはまっていたりします。

例えば、asterisk.vim を利用すると <Plug>(asterisk-z*)cgn というキー入力で

『カーソル下の単語を変更し、dot repeat で次の単語も同じ変更をする』

という事ができます。

dot repeat をうまく活用できなかった勢としては、これがかなり衝撃的でめちゃくちゃ便利でした。



が、これにも欠点があり(asterisk.vim を使う上でしょうがないんですが)『カーソル下の単語』しか対象にする事ができません。

textobj を多用する Vim でこれはちょっと不便だったので、operator-exec_commandにヘルパ関数を追加し、もう少し柔軟性を高くしてみました。

operator#exec_command#mapexpr_gn({operator}[, {noremap}])

このヘルパ関数は『{motion} のテキストを @/ に保存したあとに {operator}gn を行う operator のキーマッピング』を返します。

例えば c で dot repeat したい場合は以下のような設定になります。

" C{motion} で {motion} のテキストに対して dot repeat する事ができる
nmap <expr> C operator#exec_command#mapexpr_gn("c", 1)

dotrepeat


これにより任意の textobj({motion})に対して dot repeat する事ができるようになります。

また、c 以外のも <Plug>(operator-replace) などを適用することもできます。

nmap <expr> S operator#exec_command#mapexpr_gn("\<Plug>(operator-replace)")

これでかなり捗るようになった。

6
8
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
6
8