nano is the friendly terminal text editor found on almost every Linux server. Beyond basic editing, it can open a file at an exact line, search with regular expressions, replace text across a file, indent blocks and replay recorded keystrokes, which is exactly what you need when fixing a configuration file under pressure. This guide covers those techniques, with the shortcuts that really exist and notes on which nano versions have them.
Open a file at a known line with nano +LINE file, jump inside it with Ctrl+_ (or Alt+G), search with Ctrl+W and toggle regex with Alt+R, and replace with Ctrl+\ then A for all. Mark text with Alt+A, cut with Ctrl+K and paste with Ctrl+U. Use less or grep -n for big logs and nano for the fix. Server config editing applies to your own VPS; on shared hosting you edit only your own files.
1. Where this applies
- Your own VPS or server: you have root access, so you can edit system files such as web server, firewall and service configuration. Everything in this guide applies. Domain India VPS plans are self-managed.
- Domain India shared hosting: you cannot change server configuration. If jailed SSH is enabled on your account, you can use nano on your own files, such as
.htaccess,wp-config.phpor a script. Jailed SSH is available on every shared hosting plan; it is off by default, so ask support to enable it. Measured in September 2026, the jailed shell on our cPanel and DirectAdmin servers has nano 2.9.8, so the newest features below are not available there.
Check your version first:
nano --versionEnterprise Linux 8 systems (AlmaLinux, Rocky Linux, CloudLinux 8) ship nano 2.9; current Debian and Ubuntu releases ship nano 7 or later.
2. Open a file exactly where you need it
nano +120 /etc/nginx/nginx.conf # open at line 120
nano +120,15 /etc/nginx/nginx.conf # line 120, column 15
nano -l ~/public_html/.htaccess # show line numbers
nano -v /etc/ssh/sshd_config # view only, no accidental editsWhen an error message names a line, for example "syntax error in line 120", nano +120 puts the cursor right on it.
3. Read big logs with the right tool
nano loads the whole file into memory, so it is slow on large logs and you should never edit a log that a service is writing to. Find the line with other tools, then use nano for the configuration fix.
grep -n "PHP Fatal" error_log | tail -n 5 # find matching lines with numbers
less +G /var/log/nginx/error.log # open at the end; / to search, q to quit
journalctl -u nginx --since "1 hour ago" # systemd service logs
tail -f /var/log/messages # follow a log liveLog locations differ by system: Debian and Ubuntu use /var/log/syslog and /var/log/apache2/, while RHEL-based systems use /var/log/messages and /var/log/httpd/. On shared hosting, see Reviewing error logs in cPanel and DirectAdmin.
4. Move around a file fast
| Action | Shortcut | Notes |
|---|---|---|
| Go to line (and column) | Ctrl+_ or Alt+G | Type 120 or 120,15 then Enter |
| Top or bottom of file | Alt+\ and Alt+/ | Ctrl+Home and Ctrl+End also work in most terminals |
| Next or previous word | Ctrl+Space and Alt+Space | Ctrl+Right and Ctrl+Left in newer versions |
| Page down or up | Ctrl+V and Ctrl+Y | PgDn and PgUp also work |
| Show cursor position | Ctrl+C | Shows line, column and character count |
| Place and jump to anchors | Alt+Insert, then Alt+PgUp or Alt+PgDn | nano 6 and later only |
Anchors work like temporary bookmarks: place one on a line you keep returning to, such as an SSL block, and jump back to it later. They are not available in nano 2.9.
5. Search and replace precisely
- Search.Press Ctrl+W, type the text and press Enter. Alt+W finds the next match.
- Match case or use regex.At the search prompt, Alt+C toggles case-sensitive matching and Alt+R toggles regular expressions.
- Match whole words.With regex on, search for
\bAllowOverride\bso partial words are skipped. - Replace.Press Ctrl+\, type the text to find, press Enter, type the replacement and press Enter. At each match, press Y to replace, N to skip, or A to replace all.
- Undo if needed.Alt+U undoes and Alt+E redoes.
Example: to change every 127.0.0.1 to a new address, press Ctrl+\, enter 127.0.0.1, enter the new IP, then press A. With regex on, escape the dots (127\.0\.0\.1), because an unescaped dot matches any character.
6. Mark, copy, cut, paste and indent
| Action | Shortcut |
|---|---|
| Start or stop marking a block | Alt+A (or Ctrl+^) |
| Copy the marked block, or the current line | Alt+6 |
| Cut the marked block, or the current line | Ctrl+K |
| Paste | Ctrl+U |
| Indent or unindent the marked lines | Alt+} and Alt+{ |
| Comment or uncomment lines | Alt+3 (nano 2.9 and later, where the file type is known) |
To duplicate a server block in an nginx configuration, mark it with Alt+A, move to the end, copy it with Alt+6, move to where it should go and press Ctrl+U. Pressing Ctrl+K several times in a row collects the lines together, so one Ctrl+U pastes them all.
7. Record and replay keystrokes
nano 2.9 and later can record a sequence of keys and replay it:
- Press Alt+: to start recording.
- Do the edit once, for example: search for the next
AllowOverride None, move toNoneand replace it withAll. - Press Alt+: again to stop.
- Press Alt+; to replay the sequence at the next spot, as many times as you need.
For one simple text change across a file, search and replace (section 5) is faster; macros suit edits that involve moving the cursor.
8. Make nano your own with nanorc
Put settings in ~/.nanorc, one per line with comments on their own lines, for yourself, or /etc/nanorc for every user on your own server:
# Always show line numbers
set linenumbers
# Keep the indentation of the previous line
set autoindent
# Four-space tabs, typed as spaces (YAML does not allow tabs)
set tabsize 4
set tabstospaces
# Wrap long lines on screen without changing the file
set softwrap
# Keep the previous version as filename~ when saving
set backup
# Syntax highlighting for common file types
include "/usr/share/nano/*.nanorc"Alt+N toggles line numbers on the fly in current versions; nano 2.9 uses Alt+#.
9. Real troubleshooting examples on your own server
Fix a web server configuration error. Run nginx -t or apachectl configtest, note the file and line it reports, open it with nano +LINE, fix it, test again, and reload only when the test passes.
Change a systemd service safely. Instead of editing a unit file under /usr/lib/systemd/, which a package update can overwrite, create an override:
sudo SYSTEMD_EDITOR=nano systemctl edit myservice
sudo systemctl daemon-reload && sudo systemctl restart myserviceEdit a protected file without running nano as root. sudoedit /etc/hosts opens a temporary copy in your editor and writes it back only when you save.
Update a DNS zone file. If you run your own DNS server, jump to the record, change it, and increase the zone's serial number, or secondary servers will keep the old data. Check the file (for example with named-checkzone) before reloading.
A typing mistake in SSH, firewall or web server configuration can lock you out or take sites down. Keep your current session open, run the service's config test, and reload rather than restart where possible. With set backup in nanorc, the previous version is kept as filename~.
10. nano on Domain India
- VPS: self-managed with root access, so you install and configure nano and everything else yourself. See How to access your Domain India VPS using SSH.
- Shared hosting: jailed SSH on request, with key login only. See Enabling and accessing jailed SSH. If you prefer not to use the terminal, the control panel's File Manager has a built-in editor; see How do I use the File Manager.
For more command-line editing options, read Best ways to edit files over SSH.
How do I open a file at a specific line in nano?
Run nano +LINE followed by the file name, for example nano +120 /etc/nginx/nginx.conf. Add a column with nano +120,15. Inside nano, press Ctrl+_ or Alt+G and type the line number.
How do I search and replace all matches in nano?
Press Ctrl+\, type the text to find, press Enter, type the replacement and press Enter, then press A to replace every match. Alt+R at the prompt switches regular expressions on.
How do I copy and paste a block of text in nano?
Press Alt+A to start marking, move the cursor to select the block, press Alt+6 to copy or Ctrl+K to cut, then move to the new position and press Ctrl+U to paste.
How do I show line numbers in nano permanently?
Add set linenumbers to the file .nanorc in your home directory. You can also start nano with the -l option, or toggle line numbers with Alt+N (Alt+# in nano 2.9).
Does nano have macros?
Yes, from nano 2.9. Press Alt+: to start and stop recording keystrokes, then Alt+; to replay them.
Can I use nano on Domain India shared hosting?
Yes, if jailed SSH is enabled on your account; ask support to enable it. The jailed shell on our cPanel and DirectAdmin servers has nano 2.9.8, and you can edit only your own files, not server configuration.
Ready to work on the command line? Request jailed SSH for your shared hosting with a new support ticket, or get root access on a self-managed VPS.
A self-managed VPS gives you full root access to edit any configuration file with nano or the editor of your choice.
See VPS plans