0

I'm using fzf's Rg command to populate QuickFix window with all search results. I also have my own mappings to :cn and :cp commands.

Everything is fine except one thing when I press mapped key for :cn command new buffer is opened and the line with searched text is positioned very close to the bottom edge of window. So if I searched for function name I need to scroll down to see function's body.

Is there any way to change this behavior? I would like to position line with found text somewhere near the middle of the window.

  • Welcome to Vi and Vim! Afaik and can tell from :help :cn, this "new buffer" is not standard behavior. That said, 'switchbuf' may influence the behavior. Can you check yours? – D. Ben Knoble Nov 11 '19 at 16:11
  • My switchbuf is "usetab". I not fully understand what do you mean saying "new buffer" is not standard behavior. What is standard behavior then? – igor.sol Nov 11 '19 at 16:20
  • Ah crud, I fear I’ve misread your Q. For some reason I thought you meant :cn was opening a new split, which would be bizarre. Nvm on that fromt – D. Ben Knoble Nov 11 '19 at 16:33
2

The zz command and it’s siblings zb and zt are helpful positioning commands.

In this case, I would probably update your mapping to do zz (center cursor) after :cnext.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.