7

I am using Git bash on windows 7. Sometimes, when I am in a folder with a lot of files and when I type

$ ls

the shell displays more than one screen's worth of contents. In order to look at the complete results, I have to reach for the mouse and do some scrolling. Is there any way by which I can scroll through the shell window with just the keyboard?

[(Not so optimal)Fix 1] I know that you can achieve the result of scrolling through the results using

$ ls | less

but i feel adding the | less every time is too much work. So please don't suggest this as an answer.

[EDIT 1] The use of ls here is just as an example of any command that returns an output of more than one screen. So please don't center your answers around the ls command and offer answers that solve the problem of scrolling on the command prompt with the keyboard

2
  • @MaQleod. I notice that you have edited this post. Yet I dont see a message saying what you have edited. I am not sure whether this is the right place for this question.Where can i see what changes you have made
    – Prasanth
    Jun 9, 2011 at 5:11
  • clicking on the edit age ("1 hour ago" now) above his name will take you to the history.
    – heavyd
    Jun 9, 2011 at 5:28

4 Answers 4

1

"Scrolling the Windows [Console] With Only the Keyboard"

That the article talks about cmd.exe is irrelevant; all shells that use the Windows console work the same way in this regard.

6
  • the solution works. But I am still looking for something more elegant. With this solution, everytime I want to scroll, I have 4 extra keystrokes to do (Alt+Space, E, L and later the Esc) but I am wondering if you could do something like Ctrl + Up, Ctrl + Down to scroll without doing any of the extra stuff
    – Prasanth
    Jun 10, 2011 at 3:51
  • Sure, if you use a different console. Jun 10, 2011 at 3:52
  • which console supports that? currently, I am using Git Bash on Windows 7. I think I should look at Console2. Have you tried it ?
    – Prasanth
    Jun 10, 2011 at 4:02
  • I don't do Windows, sorry. Jun 10, 2011 at 4:04
  • 1
    This doesn't work (on Windows 10, at least) where the MINGW menu doesn't have an 'edit' entry.
    – Barney
    Oct 13, 2016 at 10:15
6

In GitBash (MingGW64) console use

  • shift+pgup
  • shift+pgdown
0

I would create the ~/.bashrc file if it doesn't exists and add a function which overrides ls to ls | less so that you always get the less-ed version.

To edit your .bashrc type:

notepad.exe ~/.bashrc

Or use whatever editor you're comfortable with. Notepad will ask you to create the file if it doesn't exist. Now add this to your newly created .bashrc and save it:

function ls() { /bin/ls "$@" | less ;}

Now you will always get /bin/ls | less and and arguments will be passed to the "ls" command, not less.

1
  • as I have mentioned in my [EDIT 1], i use ls just as an example, I am sorry if I was unclear. I cannot use your solution because, i expect to scroll with the keyboard for any command - be it ls, or ipconfig or whatever
    – Prasanth
    Jun 9, 2011 at 5:50
0

You can convert the Ctrl-PgUp/PgDown key press into a MouseWheel event using AutoHotKey, here is an article on how to do exactly that:

How to Scroll the Command Prompt Window with the Keyboard

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .