调整视觉选择的另一端

Ste*_* Lu 15 vim

我认为这将允许 vim 的视觉选择功能通过提供“切换”当前选择终点的能力来超越鼠标的效率:

图解(|应代表光标(Vim 让它在它所在字符的左侧操作)并[text]代表选定的文本,假设它们占零宽度。之间的空间的背景[ ]看起来是灰色的,并且字符立即以下|是绿色):

从...开始

Some |text here
Some second line of text
Some more text in the third line 
Run Code Online (Sandbox Code Playgroud)

v2j; 请注意该m字符包含在选择中(它现在被光标突出显示):

Some [text here
Some second line of text
Some |m]ore text in the third line 
Run Code Online (Sandbox Code Playgroud)

10l

Some [text here
Some second line of text
Some more text |i]n the third line 
Run Code Online (Sandbox Code Playgroud)

正是在这一点上,我可能决定要从不同的位置开始选择。例如,包括"Some"在第一行。

在典型的编辑器/IDE 中我别无选择。我可能不得不将手移到鼠标上,使用传统方法选择文本通常太痛苦了,使用单词跳跃Ctrl和向上/向下翻页确实有所帮助,但无论如何,我必须承诺到我开始选择之前的选择终止点之一。

所以在 Vim 中,我希望能够通过点击神秘绑定来获取我当前的状态并使其达到这个状态:

Some [|text here
Some second line of text
Some more text i]n the third line 
Run Code Online (Sandbox Code Playgroud)

然后我可以点击^<Home>(在没有前导空格的情况下两者都做同样的事情)把它变成

[|Some text here
Some second line of text
Some more text i]n the third line 
Run Code Online (Sandbox Code Playgroud)

说我变心,我要调整另一端!

[Some text here
Some second line of text
Some more text |i]n the third line 
Run Code Online (Sandbox Code Playgroud)

命中e

[Some text here
Some second line of text
Some more text i|n] the third line 
Run Code Online (Sandbox Code Playgroud)

美丽的!我现在可以用这个选择做任何我想做的事情。

那么这个神秘的绑定是什么?

此外,将一些最常用的移动命令的一组备用绑定设置为另一行键的潜在效率更高,这些将(在可视模式下)始终移动选择的另一端。所以在那个视觉模式选择操作中,如果选择另一端的移动键设置为“yuio”(可能不是一个好的选择,因为我们有点需要y但请耐心等待)我们可以输入

v2j10l5ye
Run Code Online (Sandbox Code Playgroud)

而不是

v2j10lX^Xe
Run Code Online (Sandbox Code Playgroud)

嘿,你知道吗,这甚至没有太大的改进。给我那个X功能。:)

我正在寻找的完美答案:

  • 嘿,抬头 :help some_awesome_vim_feature_that_just_does_this
  • 嘿,看看 https://github.com/awesome_user/vim_plugin_that_does_this
  • 嘿,看看 :help vimscript_functions_that_allow_mutation_of_visual_selections

我对 Vim 的这种迷恋还很陌生,所以我对 Vimscript 很陌生,老实说,我不想尝试学习另一种语言,所以希望我不会被迫将它构建为一个插件。

Hep*_*ite 53

我不确定我是否真的理解你想要什么,但也许是这样的:

:help v_o
Run Code Online (Sandbox Code Playgroud)

基本上,当文本在视觉上突出显示时,您可以按o,它会跳到视觉区域的另一“端”而无需修改它。

  • 神圣的废话,是的!!!这比我希望的还要好,它**已经绑定到一个键**,所以上面的`X`实际上是`o` (2认同)