How to add blank lines above the bottom in terminal

Kohki Mametani

In vim and many other text editors, you can scroll up the end of the file to the top of your screen while showing the rest of the lines as blank. But in terminal, by default, the end of line is fixed to the end of the terminal screen so your current line is always appearing at the bottom. How can I scroll up the current line while adding blank lines between the last line and the bottom of screen?

Thanks

egmont

The escape sequences \e[B and \e[A move the cursor down and up, respectively, constraining within the viewport. The escape sequences \eD (called "index") and \eM ("reverse index") move down and up too, but also scroll the viewport if necessary. (Note the lack of the [ character in the latter ones.)

I recommend you to print a couple of "index" characters, followed by the same number of "cursor up" (or "reverse index"). E.g.:

echo -ne '\eD\eD\eD\e[A\e[A\e[A'

moves the cursor down by 3 rows, scrolling the entire viewport if necessary, and then moves it back up. Effectively it makes sure that there are at least 3 empty lines at the bottom of the screen.

You can hook it up to your $PS1 (primary shell prompt), just make sure it's enclosed between \[ and \] so that the shell knows these characters do not horizontally advance the cursor, e.g.:

PS1='\[\eD\eD\eD\e[A\e[A\e[A\]prompt$ '

You can also choose to print it from $PROMPT_COMMAND, in which case if I remember correctly it needs to be enclosed between a 0x01 (^A) and a 0x02 (^B) byte.

Note: the shortcuts \e[3A and \e[3B move the cursor up/down by 3 rows (and obviously you can replace 3 by any number). The "index" and "reverse index" sequences don't have such shortcuts.

I'd leave it up to you as an exercise to programatically figure out your preferred number of rows based on the terminal's height.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to add multiple lines at bottom (footer) of PDF?

From Dev

How to display lines of a text in a terminal console with cleared screen at the bottom

From Dev

How to add characters to non-blank lines using vim

From Dev

How to add characters to non-blank lines using vim

From Dev

How to add alternating blank lines when saving csv file in Pandas

From Dev

How can I programmatically add an autolayout constraint to make a button 50 points above bottom of its superview?

From Dev

How to add a common view in all view controllers at the bottom above tab bar

From Dev

How to show the lines in a terminal

From Dev

How to print blank lines in Gnuplot

From Dev

Bash - Add blank line above line starting with a period

From Dev

Add and number blank line above each line in a file

From Dev

How to grep for lines above and below a certain pattern

From Dev

How to add an UIImage above UITableView

From Dev

How to add text above circle?

From Dev

How to add an UIImage above UITableView

From Dev

How to add buttons above keyboard

From Dev

How to fix error: Web with blank space at bottom

From Dev

Terminal - How to overwrite many lines?

From Dev

How to see more lines in the terminal

From Dev

How to see more lines in the terminal

From Dev

How can I add four spaces before each lines of programs code in terminal

From Dev

Vim regex: add line above all lines not starting with "#"

From Dev

Add new lines above each existing line in a file

From Dev

How do I go to the bottom of cygwin terminal?

From Dev

How to keep STDIN at bottom the terminal in C

From Dev

How To Remove Single Blank Line Only - Keep Multiple Blank Lines

From Dev

How to replace multiple blank lines with a specific non-blank line?

From Dev

How to remove blank lines in middle of a string Android

From Dev

PHP explode() - how to avoid blank lines?

Related Related

  1. 1

    How to add multiple lines at bottom (footer) of PDF?

  2. 2

    How to display lines of a text in a terminal console with cleared screen at the bottom

  3. 3

    How to add characters to non-blank lines using vim

  4. 4

    How to add characters to non-blank lines using vim

  5. 5

    How to add alternating blank lines when saving csv file in Pandas

  6. 6

    How can I programmatically add an autolayout constraint to make a button 50 points above bottom of its superview?

  7. 7

    How to add a common view in all view controllers at the bottom above tab bar

  8. 8

    How to show the lines in a terminal

  9. 9

    How to print blank lines in Gnuplot

  10. 10

    Bash - Add blank line above line starting with a period

  11. 11

    Add and number blank line above each line in a file

  12. 12

    How to grep for lines above and below a certain pattern

  13. 13

    How to add an UIImage above UITableView

  14. 14

    How to add text above circle?

  15. 15

    How to add an UIImage above UITableView

  16. 16

    How to add buttons above keyboard

  17. 17

    How to fix error: Web with blank space at bottom

  18. 18

    Terminal - How to overwrite many lines?

  19. 19

    How to see more lines in the terminal

  20. 20

    How to see more lines in the terminal

  21. 21

    How can I add four spaces before each lines of programs code in terminal

  22. 22

    Vim regex: add line above all lines not starting with "#"

  23. 23

    Add new lines above each existing line in a file

  24. 24

    How do I go to the bottom of cygwin terminal?

  25. 25

    How to keep STDIN at bottom the terminal in C

  26. 26

    How To Remove Single Blank Line Only - Keep Multiple Blank Lines

  27. 27

    How to replace multiple blank lines with a specific non-blank line?

  28. 28

    How to remove blank lines in middle of a string Android

  29. 29

    PHP explode() - how to avoid blank lines?

HotTag

Archive