Vim 转到行号时自动展开折叠

Vim 转到行号时自动展开折叠,vim,macvim,folding,Vim,Macvim,Folding,当转到行号时,是否有方法展开代码?例如,我在第35行折叠的地方键入:35,然后我必须手动展开该部分才能真正到达该行。我想键入:35,然后自动展开该代码,将光标放在第35行,无需再按任何键。zv。从:帮助zv: View cursor line: Open just enough folds to make the line in which the cursor is located not folded. 虽然这个命令可能会以某种方式自动触发,但我还没有遇到它。不过,按原样使

当转到行号时,是否有方法展开代码?例如,我在第35行折叠的地方键入
:35
,然后我必须手动展开该部分才能真正到达该行。我想键入
:35
,然后自动展开该代码,将光标放在第35行,无需再按任何键。

zv。从
:帮助zv

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

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

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

:nmap\gz ggzO

如果使用
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')

将此合并到
:au CursorMoved*:normal zv
中应该可以做到这一点。@MailenM:这将打开您移动的任何折叠,即使在使用
j
/
k
移动时,我怀疑这是否有用。
"[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')
cmap <expr> <CR> getcmdtype() == ':' && getcmdline() =~ '^\d\+$' ? 'normal! zv<CR>' : '<CR>'