Search code examples
powershellterminalscroll

Windows PowerShell shortcut to scroll to previous command


The various scroll commands in PowerShell don't seem to offer an option for scrolling to the previous command, i.e. to the top of the previous output.

So if I've executed a series of commands, each with a slew of output, and I want to review the most recent output from the top, wherever the top may be, my options include:

  • scroll up/down one line at a time
  • scroll up/down one page at a time
  • scroll to top/bottom of history/buffer

I don't know how long the output from the previous command is, so I'm just scrolling and scanning, scrolling and scanning. It's the most inefficient task of all time :-/

Is there actually a solution for this, just not well known?

Bonus: do other command line tools have an equivalent shortcut?


Solution

  • Note:

    • This answer is not a general terminal-related answer; it is specific to Visual Studio Code's integrated terminal.

    Visual Studio Code's integrated terminal offers a shell integration feature that is enabled by default and supports a number of shells, including PowerShell (open the Settings view (Ctrl+,) and type shell integration to see all relevant settings).

    With this feature enabled (as is the case by default):

    • In terms of keyboard shortcuts, Ctrl+↑ scrolls back to the prompt at which the previous command was submitted.

      • Generally, you can use Ctrl+↑ and Ctrl+↓ to navigate between command submissions.
    • In terms of GUI features (which too are enabled by default):

      • In the so-called gutter, the area to the left of the terminal display, each submitted command is visually indicated by a small blue dot.

        • When you manually scroll upward, a blue dot appearing will indicate where a command was submitted.
      • In the so-called overview ruler, which is a visually enhanced scroll bar to the right of the terminal, each submitted command is represented by a blue rectangle

        • Clicking on such a blue rectangle will scroll to that command submission.

    The following screenshot illustrates the above-mentioned GUI features: note the blue dots in the gutter on the LHS, and the blue squares in the overview ruler (scroll bar) on the RHS.

    screenshot