10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

surround.vimの拡張

10
Last updated at Posted at 2012-05-16

デフォルトのsurround.vimでは、囲み文字で囲まれた文字を削除する場合は、「di'」、「di"」の様に囲み文字を指定する必要がある。

di"

"Hello World"""

di'

'Hello World'''

自動的に囲み文字を判別してくれて、削除してくれたら便利だな、と思ったので、スクリプトを書いてみた

nnoremap ci :call <SID>ExSurround("ci")<CR>
nnoremap di :call <SID>ExSurround("di")<CR>
function! s:ExSurround(cmd)
    let pattern = "'\"{[("
    let front = strpart(getline("."), 0, col("."))
    let max = -1
    for pat in split(pattern, '.\zs')
        let pos = strridx(front, pat)
        if pos > max
            let max = pos
        endif
    endfor
    if max >= 0
        let sorround = strpart(front, max, 1)
        call feedkeys(a:cmd . sorround, 'n')
    endif
endfunction

di

"Hello World"""
'Hello World'''

対応している文字は'、"、{、[、(

※もっと良い書き方があったら押して下さいー。

10
9
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
10
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?