Vimのルビーで「do/end」と「{}」を切り替える簡単な方法はありますか?
(TextMate は でこれを行い^{
ます。)
searchpair() を使用するか、% で遊んで (matchit がインストールされていて、begin/end にいる限り)、2 つの位置をマークし、テキストかブラケットかをテストし、最後に更新する必要があります。二行。
nnoremap <buffer> <c-x>{ :call <sid>ToggleBeginOrBracket()<cr>
let s:k_be = [ 'begin', 'end' ]
function! s:ToggleBeginOrBracket()
let c = lh#position#char_at_mark('.')
if c =~ '[{}]'
" don't use matchit for {,}
exe 'normal! %s'.s:k_be[1-(c=='}')]."\<esc>``s".s:k_be[(c=='}')]."\<esc>"
else
let w = expand('<cword>')
if w == 'begin'
" use mathit
normal %
exe "normal! ciw}\<esc>``ciw{\<esc>"
elseif w == 'end'
" use mathit
normal %
exe "normal! ciw{\<esc>``ciw}\<esc>"
else
throw 'Cannot toggle block: cursor is not on {, }, begin, nor end'
endif
endif
endfunction
whereはここlh#position#char_at_mark()
で定義されています。
PS: Ruby コンテキストと高度な vim スクリプトを組み合わせているため、これは間違いなく SO の質問です。
この新しいプラグインをチェックしてください: https://github.com/jgdavey/vim-blockle .
30文字パッド