【问题标题】:Automatically expand fold when going to a line number转到行号时自动展开折叠
【发布时间】:2012-05-14 03:38:06
【问题描述】:

有没有办法在转到行号时展开代码?例如,我键入:35,其中第 35 行被折叠,然后我必须手动展开该部分才能真正到达该行。我想输入:35,然后该代码自动展开,我的光标放在第 35 行,无需任何进一步的按键操作。

【问题讨论】:

    标签: vim macvim folding


    【解决方案1】:

    zv。来自:help zv

        View cursor line: Open just enough folds to make the line in
        which the cursor is located not folded.
    

    虽然这个命令可能会以某种方式自动触发,但我还没有遇到过。不过,按原样使用命令对我很有帮助。

    【讨论】:

    • 将其合并到 :au CursorMoved * :normal zv 中应该可以解决问题。
    • @MailenM:这将打开您移动的任何折叠,即使与j / k 一起移动 - 我怀疑这是否有用。
    【解决方案2】:

    定义一个新的命令映射。在这个例子中,我选择了 \gz:

    :nmap \gz gg<Bar>zO
    

    【讨论】:

      【解决方案3】:

      如果您使用35G 命令而不是:35,则可以通过以下映射实现此目的:

      "[count]G       Also open fold under cursor when supplying [count] (i.e.
      "               jumping to a particular line, not the end of the
      "               buffer). Use [count]|gg| if you don't want this.
      nnoremap <expr> G (v:count ? 'Gzv' : 'G')
      

      对于:35 本身来说,这很难实现。您必须通过:cmap &lt;expr&gt; 拦截&lt;CR&gt;,通过getcmdtype()getcmdline() 检查键入的命令,如果是数字,则操作该命令,即将normal! zv 附加到它;像这样:

      cmap <expr> <CR> getcmdtype() == ':' && getcmdline() =~ '^\d\+$' ? 'normal! zv<CR>' : '<CR>'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-28
        • 2021-12-10
        • 1970-01-01
        • 2013-09-20
        • 1970-01-01
        • 2020-02-22
        • 2016-08-25
        相关资源
        最近更新 更多