Use Home and End Keys with the `less` Command in Linux

Abstract: Resolve Home and End key navigation issues in the less command by using native vi-style shortcuts or configuring .inputrc.

Created: 2026-09-08 by

The Home and End keys do not work in the less command by default because it uses vi-style navigation. To jump to the beginning or end of a file, press G for the last line or Shift+g for the first line. Alternatively, you can configure .inputrc to map these keys to standard readline functions.

Understanding Less Navigation Defaults

The less pager is designed to be consistent across different Unix-like operating systems. It mimics the behavior of the classic more command but adds significant functionality. One of its core design choices is the adoption of vi-style key bindings rather than emacs-style ones. This means that standard keyboard shortcuts familiar from text editors like vim are used instead of generic terminal control sequences.

When you open a large log file or source code document with less, pressing the physical Home or End keys on your keyboard often results in no action or unexpected behavior. This happens because less intercepts keystrokes before they reach the underlying shell's readline library. The terminal sends escape sequences for Home and End, but less does not have default mappings for these specific sequences in its vi-mode interface. Consequently, users who expect immediate navigation to the top or bottom of the buffer are left confused when nothing happens.

This behavior is intentional. It ensures that scripts and commands using less behave predictably regardless of the user's preferred editor. However, for interactive use, this lack of direct mapping can hinder productivity. Understanding this distinction is the first step toward resolving the issue. You must either learn the native less commands or override the terminal input processing to suit your preferences.

Native Keys for Beginning and End

The most robust solution is to use the built-in commands provided by less. These keys are universal and work on any system where less is installed, without requiring configuration changes. Memorizing these two simple characters significantly speeds up navigation through large files.

  • To go to the end of the file: Press G (uppercase). This command immediately scrolls the view to the very last line of the input stream. If the file is being streamed in real-time, such as a log file monitored with -f, pressing G will jump to the current tail position.
  • To go to the beginning of the file: Press Shift+g (or 1G). This moves the cursor to the first line. Using 1G explicitly specifies line one, which is functionally identical to the lowercase g combined with Shift in many contexts.

These commands are part of the vi motion set. They are efficient because they do not require holding down modifier keys while navigating. Once you internalize that G means "go to bottom" and shift+g means "go to top," you will find your workflow faster than relying on mouse clicks or external key remapping tools.

Configuring Readline for Key Mapping

If you strongly prefer using the physical Home and End keys, you can configure the GNU Readline library to interpret them correctly. Since less relies on Readline for input handling in its search and command modes, this change affects how those specific interactions work. Note that this method primarily influences the command-line editing aspects within less, such as when you type a search query, rather than the scrolling behavior itself.

To achieve this, edit the .inputrc file located in your home directory. If this file does not exist, you can create it. Add the following lines to map the escape sequences sent by your terminal for Home and End keys to their respective readline functions:

"\e[1~": beginning-of-line
"\e[4~": end-of-line

The sequence \e[1~ corresponds to the Home key, and \e[4~ corresponds to the End key. The function beginning-of-line moves the cursor to the start of the current line, and end-of-line moves it to the end. After saving the file, you may need to restart your terminal session or run bind -f ~/.inputrc to apply the changes. This approach integrates less more closely with standard terminal expectations.

For more advanced customization of command-line behaviors, you might also want to explore other terminal configurations. For instance, understanding how to modify exit key for less command in Ubuntu can complement your navigation setup by allowing you to quit the pager with a more comfortable key combination. Additionally, if you are managing complex shell environments, reviewing bash prompt abbreviations can help streamline your overall command-line experience.

Using Terminal Emulator Settings

Another layer of control exists at the terminal emulator level. Applications like GNOME Terminal, Konsole, or iTerm2 allow you to define what key sequences are sent when Home or End is pressed. By default, many modern terminals send ANSI escape codes that differ from older standards. You can check your terminal's preference settings to ensure it sends \e[H for Home and \e[F for End, or the bracketed versions mentioned above.

Changing these settings globally affects all applications running in that terminal window, including less, vim, and Python REPLs. This is a powerful way to enforce consistency across your development environment. However, it requires administrative knowledge of your specific terminal software. If you encounter issues where keys still do not work after configuring .inputrc, verify that your terminal is indeed sending the expected escape sequences using a tool like cat -v.

Troubleshooting Common Issues

Sometimes, even with correct configuration, navigation may feel sluggish. This is rarely an issue with less itself but rather with the size of the file being processed. For extremely large files, consider using less +G to start at the end immediately, or less +1 to start at the beginning. These flags bypass the initial scan of the file structure.

Ensure that your locale settings are correct. Incorrect character encoding can cause less to miscalculate line lengths, leading to erratic scrolling behavior. Setting LANG=en_US.UTF-8 usually resolves display anomalies. If you suspect a deeper system issue, such as disk usage discrepancies affecting file access times, you might investigate related system diagnostics. For example, checking for discrepancy in linux disk usage du vs ls can sometimes reveal storage bottlenecks that impact I/O performance during file viewing.

Frequently Asked Questions

Why do Home and End keys work in Vim but not Less?

Vim has its own internal key binding engine that defaults to mapping Home and End to the start and end of lines. Less uses the Readline library for input, which does not map these keys by default in vi mode. You must explicitly configure Readline or use Less's native G commands.

Can I make Less use Emacs key bindings instead?

Yes, you can start Less with the -e flag to enable emacs-style key bindings. In this mode, Ctrl+A goes to the beginning and Ctrl+E goes to the end. However, this changes all navigation keys, not just Home and End.

Does the .inputrc method work for scrolling?

No, .inputrc only affects command-line editing within Less, such as when typing a search pattern. It does not affect the scrolling mechanism used for moving up and down through the file content. Use G and shift+G for scrolling.

What should I do if Less freezes on large files?

Large files can cause Less to hang while scanning for compression types or calculating line counts. Use the -S option to chop long lines instead of wrapping them, which reduces processing overhead. Also, avoid piping massive uncompressed logs directly into Less without filtering.

How do I quit Less if I am stuck?

Press q to quit the Less pager. If you cannot see the prompt or the screen is garbled, try pressing Ctrl+C to interrupt the process, though this may leave the terminal in a broken state. Restarting your terminal emulator is the safest fallback.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More