【发布时间】:2012-05-14 03:38:06
【问题描述】:
有没有办法在转到行号时展开代码?例如,我键入:35,其中第 35 行被折叠,然后我必须手动展开该部分才能真正到达该行。我想输入:35,然后该代码自动展开,我的光标放在第 35 行,无需任何进一步的按键操作。
【问题讨论】:
有没有办法在转到行号时展开代码?例如,我键入:35,其中第 35 行被折叠,然后我必须手动展开该部分才能真正到达该行。我想输入:35,然后该代码自动展开,我的光标放在第 35 行,无需任何进一步的按键操作。
【问题讨论】:
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 中应该可以解决问题。
j / k 一起移动 - 我怀疑这是否有用。
定义一个新的命令映射。在这个例子中,我选择了 \gz:
:nmap \gz gg<Bar>zO
【讨论】:
如果您使用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 <expr> 拦截<CR>,通过getcmdtype() 和getcmdline() 检查键入的命令,如果是数字,则操作该命令,即将normal! zv 附加到它;像这样:
cmap <expr> <CR> getcmdtype() == ':' && getcmdline() =~ '^\d\+$' ? 'normal! zv<CR>' : '<CR>'
【讨论】: