Arrow keys in a completely text mode or terminal

Mohamad.1996

Member
Joined
Oct 5, 2019
Messages
40
Reaction score
2
Credits
242
Hi friends How can we work with arrow keys in when we are in terminal except less and more?
I've read shift + pageup and another mixed shortcut but I couldn't I think there is one way and that's less and more
Else????
 


What do you mean by work with arrow keys?
What exactly are you trying to do with the arrow keys?

Are you talking about using scroll-back?
e.g. being able to scroll back through the output of previous commands in a terminal?

Or do you mean viewing/scrolling through the output of active programs/commands?
 
What do you mean by work with arrow keys?
What exactly are you trying to do with the arrow keys?

Are you talking about using scroll-back?
e.g. being able to scroll back through the output of previous commands in a terminal?

Or do you mean viewing/scrolling through the output of active programs/commands?
Yeah I want to take a look to result of my command by scrolling up the text. cause some of commands are long.
 
OK,
In most terminal emulators the arrow keys are bound to the history - so you can scroll up and down through recent commands.

So the choices you have here are:
1. Use your terminals scroll-back AFTER the command has ran.

In order to scroll up and down through the scroll-back buffer:

On the desktop - many terminals implement a slider mechanism that you can slide up and down with your mouse, or scroll using the mouse-wheel. Typically - you can also use shift+page-up and shift+page-down to scroll through the output.

But in pure text-mode - e.g. in a virtual terminal, or a login-shell - the scroll controls are not available - but the keyboard shortcuts listed above are available.

However, there may be other keyboard shortcuts available, so check out the documentation for the terminal you are using and see what keybinds are set up. Also check to see if it has any mechanisms that will allow you to customise your key-bindings.

IMPORTANT NOTE:- most terminal emulators have a fixed limit on the amount of data that is buffered in the scroll-back. Typically between 1000 and 2000 lines. And there are some terminals like suckless.org's st (aka stterm) that DO NOT implement any kind of scroll-back mechanism.

If your command is likely to output MORE than the scrollback limit - or if your terminal DOES NOT have any scrollback capabilities - you will need to use another option.

2. Pipe your scripts/commands output to a pager/viewer
If you're running a command, or script that produces a lot of output and you want to see the output - you can pipe the output from the command/script to a pager, or viewer like less, more, w3m, lynx.
e.g.
Bash:
./YourEpicScript.sh | w3m

more and less are standard pager programs
w3m and lynx are actually lightweight, terminal-based web-browsers - but they can be used to view text-based content too.

Personally - I prefer to use less or w3m.
Both can be used with the arrow keys, but they also work with vi/vim AND emacs keybinds.

When you pipe the output to a pager or viewer, one of the advantages is that the terminal/shells scrollback buffer limit does not apply. The output that you can view can be much larger than the shells scrollback buffer.

The final option is:
3. Redirect your scripts/commands output to a file
Use this option if you don't want to view the results immediately - or if you want to have a record of the results.
e.g.
Bash:
./YourEpicScript.sh > /path/to/output-file

If you redirect to a file - you can view the results any time you like using a text editor, or a pager/viewer like more, less, w3m, lynx etc etc.

A few other things:
No scrollback:

If your terminal DOESN'T have any kind of scrollback functionality - one way to get scrollback functionality would be to run a terminal multiplexer like tmux or screen and then use tmux, or screens keybinds for accessing its scrollback mechanism.

No arrow keys:
If you're wondering why some terminal programs don't work with arrow keys, or the arrow keys don't do what you expect - it may be because many terminal programs use shortcuts that are similar to vi/vim, or emacs.

So if you're running a terminal based program and the arrow keys do not work, or do not do what you expect, try some of the vi/vim, and/or emacs keybinds.

e.g.
vim-style:
j = down
k = up
ctrl+f = page down
ctrl+b = page up
ctrl+d = half page down
ctrl+u = half page up
gg - go to top of document
G - go to end of document

emacs-style:
ctrl+n = down
ctrl+p = up
ctrl+v = page down
alt+v = page up

And the reason for these choices are historic - emacs and vim have always been popular editors on Unix and Linux based operating systems.

So, many of the standard tools use vi/vim and/or emacs style keybindings, because the binds are already familiar to vim/emacs users and it saves the them from having to move their hands away from the main keyboard to the arrow keys.

Also - back in the early days - many keyboards did not even have arrow keys.

Also - once you get used to vi/vim or emacs style keybinds - you won't miss using the arrow keys at all. Even in the programs that support using arrow keys!

For example - whenever I'm using less, I use the vi/vim style keybinds. I don't use the emacs binds or the arrow keys at all!
And I'm much more productive for it!
 
It's a little difficult to know what you are asking for here?

In Bash, you can use the up and down arrow keys to scroll through previous history commands.
 
It's a little difficult to know what you are asking for here?

In Bash, you can use the up and down arrow keys to scroll through previous history commands.
He wants to be able to use the arrow keys to view the results of a command he's ran in a terminal which has a lot of output.

So in other words, he wants to know how to access the terminals scroll-back buffer, or to be able to scroll through the output of a command using the arrow keys. Obviously, in most terminals the arrow keys are bound to the history buffer, not the scroll-back.

So I've given a bunch of ways to view all of the output from a command.
 
He wants to be able to use the arrow keys to view the results of a command he's ran in a terminal which has a lot of output.

So in other words, he wants to know how to access the terminals scroll-back buffer, or to be able to scroll through the output of a command using the arrow keys. Obviously, in most terminals the arrow keys are bound to the history buffer, not the scroll-back.

So I've given a bunch of ways to view all of the output from a command.
Thanks for your reply.
 

Members online


Latest posts

Top