2

how can I scroll or move around in the code while writing a search or command ?

I want to write a substitution :s/xxx/yyy but I forgot what yyy should be and I need to scroll a little bit to find it, but don't want to leave command line either because it took me a while to type xxx

1
  • 1
    vim preserves the incomplete command line you were typing, just press : then up arrow or ctrl-p
    – Mass
    Commented Jan 27, 2019 at 15:43

1 Answer 1

4

<C-g> and <C-t> jump to the next and previous match, respectively.

Also, if the mouse is enabled, you can probably use it (opening the command line window first might be necessary: <C-f> if already on :, q: otherwise). Opening the command-line window has some additional benefits, so is worth looking into.

However, if the replacement is difficult to remember, I’d consider this workflow:

  1. (Optional: find yyy and yank it into a register)
  2. /xxx until you’re happy with the search pattern
  3. :s//yyy or :s//<C-r>{reg} (type CTRL-r literally, using the register you yanked yyy into)
0

Your Answer

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