How do I sequentially select parts of an expression in Vim?

∥☆過路亽.° 提交于 2019-12-11 07:45:31

问题


There is a feature in Vim I would find so great.. may I ask if it exists or if anyone had an idea about how I would start implementing it?

'Inspired from Mathematica's front end's ctrl-. feature, one would be able to sequentially select, in visual mode, the successive layers of an expression the cursor is taken into. For, example, if we consider the following expression in an imaginary langage:

# enter visual mode at this position:
for(i in 1:n){
    a = append(a, b[i %% floor((n + 1) / 2)] + c - n * last(a));
                                        ^
}
---------------------------------------------------------------------------------
2                                                                 # selected text after first hit

(n + 1) / 2                                                       # second hit

floor((n + 1) / 2)                                                # third hit

i %% floor((n + 1) / 2)                                           # fourth hit

b[i %% floor((n + 1) / 2)]                                        # fifth hit

b[i %% floor((n + 1) / 2)] + c - n * last(a)                      # sixth hit

append(a, b[i %% floor((n + 1) / 2)] + c - n * last(a))           # seventh hit

a = append(a, b[i %% floor((n + 1) / 2)] + c - n * last(a));      # eight hit

for(i in 1:n){
    a = append(a, b[i %% floor((n + 1) / 2)] + c - n * last(a)); `# etc. until the whole file gets selected
}

I am aware this would require the feature to be aware of the various operators in the langage and their respective precedences, but this is not too much of an input, is it?

Any idea?


回答1:


Vim can't do that by default but there is at least one plugin that does what you want: vim-expand-region.



来源:https://stackoverflow.com/questions/27002711/how-do-i-sequentially-select-parts-of-an-expression-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!