转到行号时自动展开折叠

时间:2012-05-04 15:05:19

标签: vim macvim folding

有没有办法在转到行号时展开代码?例如,我键入{35}折叠的:35,然后我必须手动展开该部分以实际到达该行。我想输入:35并自动展开该代码,然后将光标放在第35行,而不再按任何键。

3 个答案:

答案 0 :(得分: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>拦截:cmap <expr>,通过getcmdtype()getcmdline()检查键入的命令,如果是数字,则操纵命令,即追加{ {1}}它;像这样:

normal! zv

答案 1 :(得分:2)

ZV 。来自:help zv

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

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

答案 2 :(得分:0)

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

:nmap \gz gg<Bar>zO