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