How to Open Sublime Text 2 Files from the Command Line in Linux to a Tab, Not a New Window

How can I open Sublime Text 2 files from the command line in linux to a tab, not a new window

Try Sublime command line help

subl --help
Sublime Text 2 Build 2217

Usage: subl [arguments] [files]         edit the given files
or: subl [arguments] [directories] open the given directories
or: subl [arguments] - edit stdin

Arguments:
--project <project>: Load the given project
--command <command>: Run the given command
-n or --new-window: Open a new window
-a or --add: Add folders to the current window
-w or --wait: Wait for the files to be closed before returning
-b or --background: Don't activate the application
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help (this message) and exit
-v or --version: Show version and exit

--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).

Filenames may be given a :line or :line:column suffix to open at a specific
location.

After you have opened a new window the subsequent files should be added there as per the default behavior.

How to make Sublime Text open several files in one window?

I also use a Linux distribution and when I open files from the command line they do open in the same window.

The command you are using on the command line is sublime I suspect that starts Sublime Text with the --new-window option.

Look to see if you have the /usr/bin/subl file on your system. If you do then use subl instead of sublime on the command line and see if that opens the files in the same window.

If /usr/bin/subl is not on your system then you can create it like this:

Note: /usr/bin/subl is just the Sublime Text launcher which is automatically installed on Debian based Linux distributions.

Add these 2 lines to a new file and save it as /home/user/subl:

Note: Change the path to /opt/sublime_text/sublime_text if need be.

#!/bin/sh
exec /opt/sublime_text/sublime_text "$@"

Then run these commands as a super user or with sudo, whatever is easiest with Centos:

$ chown root:root subl
$ mv subl /usr/bin/

Now you should be able to use subl on the command line to open files in Sublime Text and they should open in the same window, e.g.:

$ subl sitemap.php
$ subl robots.txt

When opening a directory through command line, Sublime text opens two windows instead of one

You are most likely using Sublime's save last session feature.

You can disable it:

http://opensourcehacker.com/2012/05/11/sublime-text-2-tips-for-python-and-web-developers/#Disable_automatic_loading_of_the_last_session

Sublime Text from Command Line

From build 3065 (Release Date: 29 August 2014) onwards Sublime text includes a command line helper, nameley subl.exe. It is at sublime's installation folder: copy it in to a folder included in the system path.
For example, in my case I copied it

from C:\Program Files\Sublime Text 3

to C:\Windows\System32

You may then use in your terminal/console subl as a command to open whatever file, such as in your example:

subl file.rb

Or you may as well modify your system PATH variable to include sublime's instalation folder, but I believe that is much more involved.

Showing the same file in both columns of a Sublime Text window

EDIT

With the release of Sublime Text 4, there is now a feature called Split View that you can access a couple different ways. Via the menu system, you can simply use File -> Split View. You can also right-click on a tab and select Split View from the context menu. It automatically opens a new pane with a new view of the file currently selected.

You should be aware that unlike the new pane described below, the new Split View pane is temporary. This means that if you click on another tab or open a new file, the split view disappears. However, the new view into the file remains open as a separate tab, so to reopen the pane (or compare any open file(s)), select the tab you want on the left, then Ctrl-click (Command ⌘-click on macOS) on the other tab(s) you want to compare, and each one will be displayed in its own pane.

If want to have two (or more) "permanent" panes that will stay open regardless of which tab you click on, just follow the directions below.


Original Answer

(For Sublime Text 3)

Yes, you can. When a file is open, click on File -> New View Into File. You can then drag the new tab to the other pane and view the file twice.

There are several ways to create a new pane. As described in other answers, on Linux and Windows, you can use AltShift2 (Option ⌥Command ⌘2 on OS X), which corresponds to View → Layout → Columns: 2 in the menu. If you have the excellent Origami plugin installed, you can use View → Origami → Pane → Create → Right, or the CtrlK, Ctrl chord on Windows/Linux (replace Ctrl with on OS X).

Using SublimeText3, how to open all files with the same name

From directly within Sublime there's no method by default that would allow you to open multiple files all at once. It's possible to add that sort of functionality via a plugin/external package. To my knowledge there isn't anything like that currently available on Package Control, but there are a lot of packages there and it may well be hiding.

Writing such a plugin is fairly simple overall since Sublime does most of the heavy lifting, but it requires a knowledge of Python. The trickier part would be figuring out what files should be opened.

On the flip side, Sublime ships with a command line helper tool called subl that talks to the running copy of Sublime and starts one as needed. Assuming that it's available on your path, opening all of the JavaScript files in a particular folder can be done that way.

tmartin:dart:~> subl *.js

That would open all of the matching files in the most recently active Sublime window; you can include -n to tell Sublime that it should open a new window first and put the files there instead:

tmartin:dart:~> subl -n *.js

This also works with folders as well as files, which adds the folders to the current window or creates a new window with that folder open.

See subl --help for more information on other available options, including opening files at an exact location.


[EDIT]

If you're using Linux or MacOS, you can extend this technique to open files in subfolders of the current folder as well, in a couple of different ways.

NOTE: The following does not apply to Windows (at least in the standard command prompts) because Windows doesn't expand file globs itself and Sublime has to do this itself, which it can do for simple globs like *.js but not for more complex ones that include folders.

If you have a shallow folder structure, you can include multiple terms on the command line. For example, if there is only one directory level deep:

tmartin:dart:~> subl -n *.js */*.js

If there are two directory levels, you need to include another term to match that due to the shell globbing rules:

tmartin:dart:~> subl -n *.js */*.js */*/*.js

For anything other than one or two levels this is rather tedious as well as error prone, in which case I would recommend using the find utility instead:

tmartin:dart:~> subl -n `find . -name '*.js'`

Here the find command searches the current folder (.) for all files with names that match *.js, which it does recursively. Once it's done the results are put into a string. Note that it's important to wrap the glob in 'single quotes' to tell the shell it shouldn't try to expand them itself.

The back ticks around the find command tell the shell to execute that first and then use the result as the arguments to the subl -n command.

The results of the find operation are relative to the start location, so you could also do something like find /Users/tmartin/projects/*.js from anywhere to find all of the appropriate files.

Windows doesn't have a find utility that works as this one does, but with a little batch file kung-fu you can create a batch file that does the same sort of thing:

@ECHO OFF

IF "%~1" == "" GOTO ERROR
subl -n
FOR /f "usebackq tokens=*" %%a IN (`dir %* /b/s`) DO subl "%%a"

GOTO DONE

:ERROR
ECHO Provide a file glob on the command line.

:DONE

This is a bit sub-optimal if there are a lot of files because it requires executing subl once for every file to be opened instead of passing them all at once, but I am far from a batch file guru.

How can I open all files in a directory with sublime text 2?

You can try

> subl dir/*

Alternatively, you can open the project in a dir > subl dir and then install EnhancedSidebar package in sublime. This allows you to select multiple file right click them and click edit. Hope this is what you're looking for.



Related Topics



Leave a reply



Submit