2

Everytime I do this:

:%s/```sh/```ctags/gc

I end up with hidden code blocks at the bottom of the screen that I can't see. I tried 'zz' but it does not work. I did read this and this but that's for normal searching. I don't know what mode I'm in when I'm in search and replace ':' to be able to use getcmdtype() ?

I tried this as well??

cnoremap <expr> n getcmdtype() =~ '[@-=:]' ? 'nzz' : 'n'
1
  • 1
    you should be able to use Ctrl-Y to scroll the screen down and Ctrl-E to scroll the screen up in the :s/.../.../gc confirmation dialog Apr 20, 2021 at 8:03

1 Answer 1

4

I think there is no good way to do what you want. However a work around could be to set scrolloff to a very large number like 999 before you start your substitution.

From :h 'scrolloff':

'scrolloff' 'so'    number  (default 0)
    Minimal number of screen lines to keep above and below the cursor.
    This will make some context visible around where you are working.  If
    you set it to a very large value (999) the cursor line will always be
    in the middle of the window (except at the start or end of the file or
    when long lines wrap).

This way each time you press n after a substitution the line will be in the middle of the screen.

3
  • Thanks, that will work. Now I just need to figure out how to turn it back off. Is there something I can do once substitution is done? So far I got this cnoremap <expr> n getcmdline() =~ '\vs\/.*gc$' ? 'yes' : 'no'. I think an autocommand might work better to turn it off and on but you answer is right.
    – ritchie
    Apr 20, 2021 at 13:26
  • Have a look at :h autocmd-events maybe you can make something with :h CmdlineLeave, checking for the last command and if it was a substitution you can reset scrolloff
    – statox
    Apr 20, 2021 at 22:52
  • yea, I'll have to look into that. Thanks.
    – ritchie
    Apr 20, 2021 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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