.最後の編集コマンドを繰り返すために使用できることを知っています。
最後のUI操作コマンドを繰り返す方法はありますか?たとえば10<C-W>-、ウィンドウを10行縮小するように記述できます。もっと小さくしたい場合は、⟨ いくつかのキー pressを押してこのコマンドを簡単に繰り返すことができると便利です。
fzなり10;ますか?どう:tabm +1?これらはすべて特別なケースにする必要がありますか?
.最後の編集コマンドを繰り返すために使用できることを知っています。
最後のUI操作コマンドを繰り返す方法はありますか?たとえば10<C-W>-、ウィンドウを10行縮小するように記述できます。もっと小さくしたい場合は、⟨ いくつかのキー pressを押してこのコマンドを簡単に繰り返すことができると便利です。
fzなり10;ますか?どう:tabm +1?これらはすべて特別なケースにする必要がありますか?
回答:
vimは以前に実行されたwincmdを追跡しないため、vimではデフォルトでこれを行う方法はありません。ただし、いくつかの巧妙なマッピングを使用してこれを行うことができます。
function! s:Wincmd(count, key)
" If count is not zero, use the original count. If otherwise, don't
" include a count.
let if_count = a:count ? a:count : ""
" This builds a wincmd from the given key, and saves it so
" it can be repeated.
let g:last_wincmd = "wincmd " . nr2char(a:key)
" Execute the built wincmd
execute if_count . g:last_wincmd
endfunction
function! s:WincmdRepeat(count)
" If no wincmd has been executed yet, don't do anything
if !exists('g:last_wincmd') | return | endif
" If a count is given, repeat the last wincmd that amount of times.
" If otherwise, just repeat once.
let if_count = a:count ? a:count : ""
execute if_count . g:last_wincmd
endfunction
" Overwrite the default <C-w> mapping so that the last wincmd can be kept
" track of. The getchar function is what captures the key pressed
" directly afterwards. The <C-u> is to remove any cmdline range that vim
" automatically inserted.
nnoremap <silent> <C-w> :<C-u>call <SID>Wincmd(v:count, getchar())<CR>
" This just calls the function which repeats the previous wincmd. It
" does accept a count, which is the number of times it should repeat the
" previous wincmd. You can also replace Q with whatever key you want.
nnoremap <silent> Q :<C-u> call <SID>WincmdRepeat(v:count)<CR>
使用するマッピングがある<C-w>場合、それらがnore多様でない場合にのみ繰り返すことができることに注意してください。を使用して発行されたwincmdは:wincmd繰り返されません。また、複数の文字を含むwincmdは実行できません(など<C-w>gf)。
:help v:count:help getchar():help nr2char():help expr1:help :wincmd:help :execute:help :for:help :map-<silent>:help c_CTRL-U:help <SID>.のカウントでの動作とは異なる動作をします。にカウントが提供される.と、前のカウントは無視されます。だから、2dd続く3.2行、その後、3行を削除します。対照的に、マッピングでは、2<C-w>-その後に3Q2行、次に6(= 2x3)行でウィンドウが縮小されます。この動作は問題ありませんが、カスタムコマンドの動作を選択する際に、類似の組み込みVimコマンドから描画するのは良いことです。
repmo.vim(「繰り返しモーション」)と呼ばれる別のプラグインがあります。
ただし、繰り返したいモーション(または一般的なアクション)を指定する必要があります。私の現在の設定は次のとおりです。
let g:repmo_mapmotions = "j|k h|l zh|zl g;|g, <C-w>w|<C-w>W"
let g:repmo_mapmotions .= " <C-w>+|<C-w>- <C-w>>|<C-w><"
let g:repmo_key = ";"
let g:repmo_revkey = ","
だから、5 CTRL-W +私は;同じように何度でもそれを繰り返すためにヒットすることができます。
プラグインは、指定された各キーのマッピングを作成することにより機能します。
ときfまたはt使用されている、;と,のマッピングは、デフォルトの動作に戻ってクリアされます。
g;以前の編集ポイントに戻るために、マッピングが特に便利だと思います。 g; ; ; ;
,はすぐに行動し、5,期待どおりに機能します。それはあなたが設定されている可能性であるmapleaderには,?