36

In emacs, you can open new files with Ctrl+X, Ctrl+F

And go to the previous file with Ctrl+B, and go to the next file with Ctrl+N.

How to do this in nano text editor? While nano is launched, and then open new files, and how to switch between the opened files in the nano text editor?

Vlastimil Burián
  • 3,024
  • 2
  • 31
  • 52
s-hunter
  • 24,172
  • 16
  • 88
  • 130
  • Ctrl+B is back one character; Ctrl+N is forward one line. Not sure if these bindings were there 4 years ago as well! – hjpotter92 Aug 31 '18 at 22:13

5 Answers5

45

Put "set multibuffer" into ~/.nanorc or start nano with -F. Toggle this inside nano with alt-F. You can now read files into their own buffer with ctrl-R.

Use alt-comma and alt-period to go forward and backward in the file list.

NULL
  • 2,549
  • 1
  • 15
  • 17
  • 1
    Thanks. But the go forward and backward should be alt-> alt- – s-hunter Nov 06 '13 at 18:22
  • 3
    If you are using OSX and ssh into a Linux box to use Nano on the Linux box. Make sure you use Alt+Cmd+O to change OSX Terminal's behaviour to treat Alt as Meta else it is impossible to switch between two buffers! – sumitkm Dec 14 '17 at 22:47
  • @s-hunter alt+arrow keys just beep and say "Unknown command". alt+comma and alt+period work for me. – Michael Jun 10 '22 at 19:46
  • 1
    ALT-F is no longer bound at the top level menu - to open a new file, go to the insert/ctrl-R menu and toggle it from there. It switches between 'File to insert' and 'File to read into new buffer'. I don't know what version changed this but it happened [in 2018](https://git.savannah.gnu.org/cgit/nano.git/commit/?id=772c324f25f90cc0f17abf2c72f85e72350b77eb) – Peter Hull Aug 10 '23 at 13:19
13

To switch between open files in nano

alt+. -- move forward one file

alt+, -- move back one file

Steps

Open as many files as you want by listing them as separate arguments to nano, like so:

nano file1.txt file2.log file3.c file4.js file5.py

The first file is opened, e.g. file1.txt. Use the keyboard shortcuts below to switch between the files.

alt+. -- move forward one file

alt+, -- move back one file

nano --version GNU nano, version 2.9.3

activedecay
  • 10,129
  • 5
  • 47
  • 71
12

If you've already got nano open and you want to open a new file it's quite simple when you've figured out the keys...

  • Ctrl+R to open the insert dialog
  • EscF can be used to change the insert mode between current buffer and a new buffer
  • Ctrl+X allows you to execute a command with the output going into the buffer
  • Ctrl+T will open a simple browser to select a file
Lenny
  • 121
  • 1
  • 2
1

Building off of the other answers, here's my take on it:

Switch between open buffers with alt+left arrow and alt+right arrow. Nano will tell you which buffer you are in (the name of the file and the buffer number).

To open multiple files when you're starting up nano, do exactly what activedecay said (type such as nano file1.txt file2.txt file3.txt). Note you can also do such as nano *.txt to open all the txt files that are in the current directory, each in its own buffer.

To open a new and empty buffer after nano is already open, follow these steps:

  1. Press ctrl+t
  2. Press alt+f
  3. Press enter

If you already have an open buffer, and want to open a file into a new buffer, do what Lenny's answer says:

  1. Press Ctrl+r
  2. Press alt+f (or press Esc and then press f)
  3. Type the name of a single file to open in a new buffer
  4. Press enter

As to how to how to open multiple buffers at once from already existing files when you're already in nano, I'm not sure, yet.

Ctrl+x closes the current buffer.

I tested these things on nano 5.5 in Termux 0.106 (and nano 6.3 on Termux 0.118.0) on Android 10, with a bluetooth keyboard. I mention the version because shortcuts in at least some previous versions, if not all of them, aren't the same.

Brōtsyorfuzthrāx
  • 4,387
  • 4
  • 34
  • 56
  • In `nano4.8` (on focal fossa) `ctrl+t` is speller. For empty new it is `ctrl+r` and `enter`. If you meant `ctrl+t` after `ctrl+r` then there is no `alt+f`. – Multifix May 26 '22 at 09:44
  • @Multifix Even the newest versions of Ubuntu come with sorely outdated versions of nano. Don't ask me why. The answer is different for older versions (but the answer is the same for nano version 6.3 as for nano version 5.5). You can compile the new version and install it pretty easily, though. I've done that on Xubuntu (not the newest version of Xubuntu). The keys and order in my answer are what I meant. – Brōtsyorfuzthrāx May 26 '22 at 23:31
  • alt+arrow keys just beeps at me and says "Unknown command" – Michael Jun 10 '22 at 19:45
  • @Michael What version of nano are you using, and on what operating system? – Brōtsyorfuzthrāx Jun 10 '22 at 21:32
  • 1
    @Brōtsyorfuzthrāx hmm, looks like it's pretty old... v 2.2.4 on SunOS – Michael Jun 10 '22 at 22:19
1

Steps:

  1. Press Ctrl + r
  2. Press Alt + f to open the file
  3. Type the name of the file to open it
  4. Press enter
  5. Use alt + arrow keys to switch files
Louiskoder
  • 48
  • 8