Jump Directly to a Line in GNU Nano with Ctrl+_
Use Nano’s Ctrl+_ shortcut to jump straight to any line number. Learn how it works, see a step‑by‑step example, and avoid common mistakes for efficient navigation in large files.
03 Dec 2025, 16:40 UTC

Jump Directly to a Line in Nano
When editing large configuration files or source code, you often need to move the cursor to a specific line number. GNU nano’s Go‑to‑Line command, invoked with Ctrl+_ (underscore), lets you do exactly that in one keystroke.
How the Feature Works
Nano keeps the entire file in memory. When you press Ctrl+_, it brings up a prompt at the bottom of the screen:
Go to line:
You type the desired line number and press Enter. Nano then scans the in‑memory buffer, counting newline characters until it reaches the requested line. The cursor lands at the beginning of that line. If the number exceeds the file’s length, the cursor snaps to the final line, which can be misleading if you’re not aware of the file’s size.
Practical Example
- Open a file with many lines:
nano /etc/nginx/nginx.conf - Press
Ctrl+_.- On the prompt, type
250and pressEnter. - The cursor jumps to line 250, ready for editing.
- On the prompt, type
- To verify the line count, run in another terminal:
wc -l /etc/nginx/nginx.conf. The number should be at least 250. - Try an out‑of‑range number, e.g.,
999999. Nano will move to the last line and display a warning message:Line number too high, moving to last line.
Common Mistakes to Avoid
- Confusing shortcuts:
Ctrl+Gopens the help screen,Ctrl+Tstarts spell‑checking. Remember thatCtrl+_(underscore) is the correct key. - Not pressing
Enterafter typing the line number—Nano will not jump until the command is confirmed. - Using a line number that doesn’t exist; the cursor will end up at the last line, potentially causing mis‑edits.
- Assuming the feature works on a file that isn’t fully loaded (e.g., a remote file streamed through
less); nano must have the complete file in memory.
Limitations and Edge Cases
- Large files consume RAM because nano loads the entire file. On systems with limited memory, this can lead to performance degradation.
- Nano versions older than 2.2.6 do not support
Ctrl+_. Verify your version withnano --version. - When the file contains non‑UTF‑8 characters, line counting may misbehave, though this is rare for typical config files.
Quick Verification Checklist
- Open the file in nano and press
Ctrl+_.- Enter a known line number (e.g., 10). The cursor should appear at that line.
- Enter a number larger than the file’s line count. Nano should move to the last line and display a warning.
- Outside nano, run
wc -l filenameto confirm the total line count matches your expectations.
Conclusion
The Ctrl+_ shortcut is a quick, keyboard‑only way to navigate large files in nano. By understanding its behavior, verifying line counts beforehand, and avoiding common pitfalls, you can edit complex files more efficiently.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.