Whenever I move the cursor left or right using h or l, the fold under the cursor opens automatically. By the way, moving top or down does not have this problem. Is there any way to prevent automatically opening fold when moving horizontally?
You can create the auto command:
autocmd! CursorMoved * if foldclosed('.') != -1 |
\ nnoremap h <nop>|
\ nnoremap l <nop>|
\ else |
\ silent! unmap h|
\ silent! unmap l|
\ endif
Here foldclosed('.')
returns -1
if current line is unfolded. Instead of using this auto command just avoid pressing h
or l
over folds.
The default value of :help 'foldopen'
has hor
in it; this causes horizontal movements (like l
, h
) to open folds.
To disable this, simply add this to your ~/.vimrc
:
set foldopen-=hor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With