有没有一种方法可以模仿ReSharper的“扩展选择”。的功能? [英] Is there a way to emulate ReSharper's "extend selection" feature in Vim?
问题描述
ReSharper具有一个很好的功能,称为扩展选择:通过反复按 CTRL + W
(我认为这是默认设置),您可以从当前菜单中选择越来越多的内容。插入位置。首先是一个单词,然后是越来越多的单词,一条线,内部的然后是外部的行块(例如,if块),然后是一个函数,等等...
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 caret location. First it's a word, then more and more words, a line, inner then outer block of lines (for example an if-block), then a function, etc...
基本上,通过反复按组合键,您最终可以选择整个文件。我敢肯定至少你们中的一些人会熟悉它。
Basically, by pressing the key combination repeatedly, you can end up selecting the entire file. I'm sure at least some of you will be familiar with it.
我刚刚开始学习vim的所有复杂性,但我没有足够的经验来了解如何在Vim中实现这样的功能(尽管我认为这是可能的)。因此,我的问题是针对Vim专家的:可以做到以及如何做到?
I have just started learning all the intricacies of vim and I don't have enough experience to see how something like this could be implemented in Vim (although I assume it's possible). So my question is meant for Vim gurus out there: can this be done and how?
更新:有点背景故事。我一直在和我的前老板谈论Vim的所有好处,他认为这一切都很棒。他唯一的问题/问题是:它具有扩展选择吗?到目前为止,我的问题是 no 。因此,如果有人知道答案,我将最终赢得讨论:P(也许可以创建一个新的Vim convert :-)
)
Update: a bit of a background story. I've been talking to my ex-boss about all the benefits of Vim, and he thinks it's all great. His only question/problem was: does it have "extend selection"? My question so far has been no. So, if someone knows the answer, I'll finally win a discussion :P (and maybe create a new Vim convert:-)
)
推荐答案
我快速解决了这个问题。它无法按原样工作。随意进行编辑并发布在vim Wiki上,或者如果您精炼的话也可以将其发布。
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.
您是否想为每种语言制作ag:resharp_list (例如,一种用于非母语的语言,等等。)
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 \<esc>v" . g:resharp_select[g:resharp_index]
let g:resharp_index = g:resharp_index + 1
endfun
nnoremap <c-w> :call ResharpSelect()<cr>
vnoremap <c-w> :call ResharpSelect()<cr>
"Something to reset on timeout. TODO this doesn't work
au CursorHold :let g:resharp_index = 0<cr>
这篇关于有没有一种方法可以模仿ReSharper的“扩展选择”。的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!