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
  •  | 
  •  

Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top