3

In my folder I have a bunch of .cpp files. I use nano for editing my files. Is there a way for me to be able to write a single command and open all the .cpp files in different tabs?

If I do nano *.cpp, the next file opens after I close the current one and that isn't the desired behavior. The desired behavior is that all files open simultaneously in tabs.


I'm using MTPuTTY.

  • I'm not too familiar with nano, but does it support tabs natively? Or are you meaning tabs in your window manager? – Jeff Schaller Oct 20 '15 at 14:20
  • @JeffSchaller: I don't know myself if it support tabs natively. At least in nano --help there was no such option. I want that every file opens in a new tab of window manager. – displayName Oct 20 '15 at 14:24
  • 1
    I'd suggest editing your question to include your window manager in the description and the tags, in the hopes of getting someone who's knowledgeable in that WM. – Jeff Schaller Oct 20 '15 at 14:25
2

Based On details in The comments it seems that you are running from a windows machine using putty. Due to limitations with the putty connection, You would need x forwarding to use a native terminal to have multiple tabs (as your putty terminal each tab is a separate connection, controlled by windows rather than being a single point of access to the linux machine). As a result your best option is to use an editor that has built in tab support (which to my knowledge nano unfortunately does not). If you are up for using vim as an alternative, it does support tab's as an option.

You can open all your items in vim in separate tabs with

vim -p *.cpp

then control them further with the following:

:tabe <file>  #Opens  <file> in a new tab
:tabp         #Switches to previous tab
:tabn         # switches to next tab

Alternatively you can use window splits

:split        # Opens a second editor in a horizontal split
:vsplit       # Opens a second editor in a vertical split

ctrl-wctrl-w Jumps between splits.

Or Multiple buffers

:e <file>     #edits opens <file> in a new buffer
:bn           # switches to the next buffer
:bp           # switches to previous buffer

The real usage would be a combination of all three. Us multiple tabs to have different configurations of window splits for different purposes, and switch window split buffers between different buffers as you need them.

As a final Alternative, if you download an ssh client that supports x forwarding, I use mobaXterm You could run something like gnome-terminal (Assuming you have, or can install a Window Manager) as a GUI program from the Linux system, and possibly get your tab solution that way as well.

  • Is it doable to make use of the window manager to open the files in new window tabs? – displayName Oct 20 '15 at 14:27
  • What windows manager are you using? I see you added a putty tag, does this mean you are on a windows machine connecting to a linux box through putty? – Gravy Oct 20 '15 at 14:30
1

Nano can edit multiple files at the same time, but it doesn't have a visual element to switch between files. Use the keyboard shortcuts Alt+< and Alt+> to navigate between open files.

Press Ctrl+G in nano to see the list of keyboard shortcuts.

Rather than running an editor on the remote machine, which can be annoying especially if the connection drops, I recommend running an editor locally. Good editors can edit remote files, using one of PuTTY's companion programs plink, pscp or psftp to copy files. If you can't think of a good editor, use Emacs, which is available under both Windows and Linux. Emacs can access remote files very easily, but under Windows this might require some setup to tell it to use plink; see e.g. this tutorial or this question.

  • Observed one of the strangest behaviors yet... The key combination Alt + < works with left Alt and not with the right Alt key on keyboard. – displayName Oct 26 '15 at 15:41
  • @displayName In many keyboard layouts, right Alt is AltGr, not Alt. On Windows, AltGr is simulated as Ctrl+Alt, and I think applications can't tell that AltGr was pressed rather than Ctrl+Alt. – Gilles Oct 26 '15 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.