Is there a way to emulate ReSharper's “extend selection” feature in Vim?

前端 未结 5 632
轮回少年
轮回少年 2021-02-09 04:32

ReSharper has a nice feature called \"extend selection\": by pressing CTRL+W (I think this is the default) repeatedly, you select more and more from your current ca

5条回答
  •  遇见更好的自我
    2021-02-09 05:12

    I had a quick go at this problem. It doesn't work as is. Feel Free to make edits and post on the vim wiki or as a plugin if you get it refined.

    chances are you'd want to make a g:resharp_list for each language (eg. one for paranthesised languages, etc.)

    All that is needed is a marker for the original cursor position :he markers and a timeout autocommand that resets the index.

    "resharp emulator
    "TODO this needs a marker
    "also c-w is bad mapping as it has a lag with all the other-
    "window mappings
    "
    let g:resharp_index = 0
    
    let g:resharp_select =  ['iw', 'is', 'ip', 'ggVG']
    
    func! ResharpSelect()
        if g:resharp_index >= len (g:resharp_select)
            let g:resharp_index = 0
        endif
    
        exe "norm \v" . g:resharp_select[g:resharp_index]
        let g:resharp_index = g:resharp_index + 1
    endfun
    
    nnoremap   :call ResharpSelect()
    vnoremap   :call ResharpSelect()
    
    "Something to reset on timeout. TODO this doesn't work
    au CursorHold :let g:resharp_index = 0
    

提交回复
热议问题