[英]In vim, how can I map a key to toggle folding over the whole buffer?
I'd like to map a key to toggle between foldmethod=indent
and no folding. 我想映射一个键来在foldmethod=indent
和no folding之间切换。 How can I do that? 我怎样才能做到这一点?
I'd say z i (toggle foldenable) does the job. 我会说z i (toggle foldenable)完成这项工作。 No mapping required. 无需映射。 (see also :he folding
) (另见:he folding
)
( You could also look at z M and z R ) ( 你也可以看看z M和z R )
Since you want to map it to a single key, proceed as follows: 由于您要将其映射到单个密钥,请按以下步骤操作:
:nnoremap <F10> zi
To force the foldmode to indent
each time (not really recommended for me), you'd need a function: Add the function to your vimrc[2]: 要强制折叠模式每次indent
(不是我真的推荐),你需要一个函数:将函数添加到你的vimrc [2]:
function ForceFoldmethodIndent()
if &foldenable
se foldmethod=indent
endif
endfunction
nnoremap <F10> :normal zi^M|call ForceFoldmethodIndent()^M
inoremap <F10> ^O:normal zi^M|call ForceFoldmethodIndent()^M
Let me know if that works for you. 如果这对您有用,请告诉我。 I appreciate if you accept this answer if it does :) 如果你接受这个答案,我很感激:)
Cheers 干杯
[1] with behave mswin
[2] To enter the special keys (eg ^O
) in commandline or insertmode use eg [1] with behave mswin
[2]在命令行或insertmode中输入特殊键(例如^O
)使用例如
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.