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'
ritchie
  • 253
  • 1
  • 9

1 Answers1

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.

statox
  • 49,782
  • 19
  • 148
  • 225
  • 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 '21 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 '21 at 22:52
  • yea, I'll have to look into that. Thanks. – ritchie Apr 20 '21 at 23:19