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
    vim preserves the incomplete command line you were typing, just press : then up arrow or ctrl-p – Mass Jan 27 '19 at 15:43

<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)
  • Unless I’m missing something CTRL-G and CTRL-T only work for /, which is a shame – Tae Apr 18 '20 at 7:13

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.