【问题标题】:What's a common use case of "selection mode" in vim?vim 中“选择模式”的常见用例是什么?
【发布时间】:2016-11-16 11:24:22
【问题描述】:

这是我第一次注意到 vim 中的 选择模式,当时我不小心从 visual-line 模式被 <c-g> 触发了它。

Vim 已经有 visual mode 用于文本选择 selection mode 的用例是什么,谁能给我一个提示?

(注意:我已经检查了将其描述为的手册页

类似于 MS Windows 文本选择

但我还是不太明白为什么我们需要在 vim 中进行任何鼠标操作)

【问题讨论】:

    标签: vim


    【解决方案1】:

    select-mode 常用于vim-snipmate等sn-p插件。可以创建选择模式独有的映射,以免干扰常规视觉模式行为。

    以下是 Drew Neil 的 Practical Vim 的摘录:

    如果您乐于接受 Vim 的模态特性,那么您应该 选择模式几乎没有什么用处,它掌握着用户的手 想让 Vim 表现得更像其他文本编辑器。我能想到 只有一个地方我一直使用选择模式:当使用 模拟 TextMate 的 sn-p 功能的插件,选择模式 突出显示活动占位符。

    【讨论】:

    • 真的很感激! “很高兴听到”的回答。
    【解决方案2】:

    正如文档所暗示的,select modevisual mode 有点不同。以下是您可以在其中执行的命令:

    Commands in Select mode:
    - Printable characters, <NL> and <CR> cause the selection to be deleted, and
      Vim enters Insert mode.  The typed character is inserted.
    - Non-printable movement commands, with the Shift key pressed, extend the
      selection.  'keymodel' must include "startsel".
    - Non-printable movement commands, with the Shift key NOT pressed, stop Select
      mode.  'keymodel' must include "stopsel".
    - ESC stops Select mode.
    
    - CTRL-O switches to Visual mode for the duration of one command. *v_CTRL-O*
    - CTRL-G switches to Visual mode.
    
    Otherwise, typed characters are handled as in Visual mode.
    
    When using an operator in Select mode, and the selection is linewise, the
    selected lines are operated upon, but like in characterwise selection.  For
    example, when a whole line is deleted, it can later be pasted halfway a line.
    

    您可以查看文档here

    他们所说的“类似于 MS Windows 选择”的意思可能是您可以使用Shift+Arrows 扩展选择,并且输入的任何可打印字符都将替换所选文本并输入insert mode

    另外,请参阅this question/answer at the vi.SE

    【讨论】:

    • 感谢您的努力!我知道 Doc 总是值得去的地方,只是有时为了我的知识范围,它们被高度概括了?
    猜你喜欢
    • 2023-02-02
    • 2011-11-24
    • 1970-01-01
    • 2012-09-24
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 2011-03-21
    相关资源
    最近更新 更多