When custom mapping is set for :cn, :cp vim doesn't expand the fold that contains an error

StackOverflow https://stackoverflow.com/questions/16703362

  •  30-05-2022
  •  | 
  •  

I have noticed that when I use :cn :cp directly, vim always expands folds for me. But when I set my custom mapping to call :cn like :map <leader>n :cn<cr>, vim doesn't expand foldings when I use <leader>n in this case, I have to move horizontally after using that hotkey to unfold. I could script moving horizontally as well, but I still would like to understand why vim doesn't do that for me. My foldopen setting contains quickfix.

Thanks.

有帮助吗?

解决方案

According to this vim email archive.

This is the correct behavior and that you are supposed to open folds manually if you put :cn or :cp into mappings. The solution was to add zv to the end of the mappings.

So your maps should look like this

noremap <leader>n :cn<CR>zv

Note: I change map to noremap because noremap stops recursive mappings whereas map allows for it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top