Nano | line numbers & copy / paste *

So to toggle line numbers in Nano:

Key ComboWhat to Press on Mac
Alt + #Option + Shift + 3
ORTap Esc, then Shift + 3

Open files with / without line nubers in Nano:

You can enable line numbers when opening files in one of two ways:

  1. Launch Nano with the -I Flag: Open your file with:

    nano -l filename
    

This displays line numbers for that session.

  1. Set Line Numbers Permanently in nanorc: Add the following line to your ~ / . nanorc file:

    set linenumbers
    

This will show line numbers every time you launch nano. To hide line numbers, simply omit the – 1 flag when launching nano or remove/comment out the set linenumbers line in your ~/.nanorc file.


✅ Nano Flow on macOS

ActionKey ComboNotes
Set markCtrl + Shift + 6 (^)Highlights starting point
SelectArrow keysMoves cursor to highlight
CopyEsc, then 6Grabs selection (Meta+6)
PasteCtrl + U (or Option + U if Meta is mapped)Pastes in Nano

 

🛠 Bonus: Terminal Preferences (Optional)

If none of the key combos work, open Terminal > Settings > Keyboard and:

  • Check "Use Option as Meta key"
  • Or remap keys if needed

Alternatively, using iTerm2 instead of macOS Terminal gives you much better key handling.




🎯 In Nano:

  • M stands for "Meta", not Control.

    • On most systems (especially macOS), Meta = Esc or Option (depending on your Terminal settings).
    • Ctrl is written as ^, like ^K = Ctrl+K.

🔑 So for Copy (M-6), here’s what it actually means:

  • M-6 = Meta + 6

    • On macOS, this typically means:

      • Tap Esc, then press 6 (don’t hold Esc — just tap and release, then 6)
      • Or try Option+6 if Terminal is set to use Option as Meta (check Terminal settings)

✅ First: Keybinding Terminology on macOS

  • M- means "Meta", which is usually the Option key on Mac.

  • Sometimes Terminal needs Esc used as Meta instead.

  • So for example:

    • M-^Esc, then ^ (i.e. Ctrl+^)
    • M-6Esc, then 6

You can try tapping Esc first, then pressing the next key, instead of using Option.


✅ What should happen when "Set Mark" works:

  1. You press: Ctrl + ^ (that's Ctrl + Shift + 6) or on Mac: Esc, then ^

  2. Nano will show Mark Set in the status bar at the bottom.

  3. Then when you move your cursor with the arrow keys, Nano will visually highlight the selected area.

  4. Once you’ve highlighted the desired text:

    • Press Esc, then 6 to copy
    • Then go where you want and press Ctrl+U to paste

🤔 If you see nothing:

  • No “Mark Set” message? That means it didn’t register.
  • Try tapping just Ctrl + Shift + 6 again (you won’t see anything happen until you move the arrow keys).
  • If that fails, tap Esc, then press ^ (which is usually Shift+6) and see if that works.

🧪 Quick test to verify:

  1. Open any file in nano: nano test.txt
  2. Move to a word
  3. Press Ctrl + Shift + 6 You won’t see anything yet, but it sets the mark
  4. Press the right arrow key → Now you should see text being highlighted If you do, it's working!

Let me know what you're seeing after you press the mark combo — no message, message but no highlight, etc. We’ll get this working.

 

 

🔧 How to Mark + Copy in Nano on macOS

Step-by-step without using mouse:

  1. Set the mark:

    • Tap Ctrl + ^ (Ctrl+Shift+6) If this doesn't work, try: Esc then ^
  2. Move with arrow keys to highlight the region

  3. Copy the selection:

    • Tap Esc, then 6 Or: try Option+6 if your Terminal supports it (Some Macs might use Fn+Option+6 depending on keyboard)
  4. Paste:

    • Ctrl+U

🧪 Test it:

If you’re unsure it's marking:

  • After Ctrl+^ you should see the bottom bar show “Mark Set”.
  • If that doesn’t happen, your terminal might be swallowing the shortcut.

 

✅Nano’s Built-in Copy

Instead of using the mouse:

  1. Set mark with Ctrl+^ at the start of what you want to copy.
  2. Move the cursor to the end of the text to select it.
  3. Use Alt+6 to copy (this is Nano's internal copy).
  4. Move the cursor where you want to paste and hit Ctrl+U.

This won't include line numbers.

✅ Solution 2: Temporarily Turn Off Line Numbers

If you're just copying a big chunk:

  • Hit Alt+# (or M-#) to toggle line numbers off before selecting with your mouse.
  • Turn them back on the same way afterward.

✅ Bonus: Add a Toggle Shortcut in .nanorc

If you want to easily switch line numbers:


bind M-l linenumbers main

Then pressing Alt+L toggles line numbers on/off.

Let me know if you want to keep line numbers but exclude them from copy in some automated way — there are tricks for that too.


✅ Summary of Important Nano Keys

FunctionKey ComboNotes
Set markCtrl + ^ (Ctrl + Shift + 6)Sets selection start
CopyMeta + 6 (usually Esc, then 6)Copies marked text
PasteCtrl + UPastes at cursor
CutCtrl + KCuts marked region

If you want, I can show you how to remap Meta to make this easier, or even make custom bindings in .nanorc. Want to go that route?

 

🔄 Can You Paste Between Machines?

This is where Nano’s internal copy buffer has limits:

🟥 No: Nano copy/paste is not shared between windows or machines

  • The copy you make with Esc + 6 (internal to Nano) is only stored in Nano’s own buffer.
  • It does not go to your system clipboard.
  • So you can’t paste it into another Terminal window, or to another machine via SSH, unless you use a different method.

✅ But You Can Do This Instead:

1. Use your mouse to highlight & copy (if line numbers are off)

  • You can select with your mouse, and then paste anywhere else — even across SSH sessions, machines, apps.

2. Use pbcopy (macOS clipboard) to copy from Nano

If you're using macOS and want to copy Nano content to your clipboard:

  • Save your text or block to a file

  • Then run in Terminal:

    
    cat yourfile.txt | pbcopy
    
  • Now you can paste it anywhere, even across machines.


💡 Want clipboard support inside Nano?

You can use:

  • nano in a GUI terminal that supports system clipboard (like iTerm2 with mouse support and "Copy on select")
  • Or use a tool like xclip or tmux with clipboard integration, but that’s more advanced

🔁 Toggle line numbers in Nano (while editing):


Alt + #

On a Mac, that usually means:

  • Option + 3 (since # is Shift+3 on US keyboards)
  • Or just tap Esc, then press #

When you hit that, it’ll instantly turn line numbers off (or back on) without needing to restart Nano.


🛠 Optional: Disable line numbers permanently

If you added this to your ~/.nanorc:


set linenumbers

Then just comment it out or remove it:


# set linenumbers

Save the file, and line numbers will be off by default next time you open Nano.

Scroll to Top