6

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

4

3 回答 3

7

如果您使用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其本身而言,这将很难实现。您必须<CR>通过 a拦截,通过and:cmap <expr>检查键入的命令,如果是数字,则操作命令,即附加到它;像这样:getcmdtype()getcmdline()normal! zv

cmap <expr> <CR> getcmdtype() == ':' && getcmdline() =~ '^\d\+$' ? 'normal! zv<CR>' : '<CR>'
于 2012-05-04T18:31:17.310 回答
2

zv. 来自:help zv

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

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

于 2012-05-04T15:47:14.697 回答
0

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

:nmap \gz gg<Bar>zO
于 2012-05-04T15:52:12.703 回答