问题
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