Sublime Forum

How do I split window for single file?

#1

My main page of website has 5000 line code. I want to see line 250 and 3600. In single file how do I to see split view.

0 Likes

#2
  • File menu -> New View into File
  • View menu -> Layout -> Columns: 2 or Rows: 2
  • drag the tab into the other group
3 Likes

#3

I think that option only moves the file from one panel to the other, at least that is what happened when I tried it. The OP wanted to split the file. The only way I know, is to duplicate the file and run both files side by side.

0 Likes

#4

Sublime splits are different than Emacs- or Vim-style. Window splits are really more like creating a new window that happens to be rendered within the existing one.

0 Likes

#5

As has been mentioned, Sublime’s method of supporting this is to change the view layout, creating a clone of the current view and then shifting the file to that new view, as @kingkeith mentioned in his post above.

There are some limitations here:

  • The cloned view starts at the top of the file and not at your current editing position
  • You need to manually shift the view to the other view group
  • The built in options for view groups are not particularly dynamic (the default options are static and limited).

The Origami plugin provides a ton of functionality in this area. It can dynamically split the current view without otherwise changing the layout, shift a view to a different panel, clone the current view to an adjacent panel and more (personal favorite: save and reload a view layout for various tasks).

One of the nice things is that when you use it to clone a view, it positions the cursor in the cloned view at the same position it was originally in.

Using it you can get the workflow to split the current panel horizontally or vertically and then clone the current view into the new panel down to two keystrokes. Using your favorite customization technique you could use a plugin to execute multiple commands, create menu entries, add to the command palette, etc.

As a simplistic example, something like this plugin would create a command that splits the current view horizontally and puts a clone of the current view into the new lower panel. It could be bound to a single key stroke for quick splitting action.

import sublime
import sublime_plugin


class CloneBelowCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.window.run_command ("create_pane",        {"direction": "down"})
        self.window.run_command ("clone_file_to_pane", {"direction": "down"})
2 Likes

#6

So I found this six years later (Hi to OdatNurd!) and looks like something has changed with Sublime 4.
The TL:DR is to delete the “create_pane” line.

The background for hopeless newbies like me:

https://docs.sublimetext.io/guide/extensibility/plugins/

Conventions for Command Names
You may have noticed that our command is named ExampleCommand, but we passed the string example to the API call instead. This is necessary because Sublime Text standardizes command names by stripping the Command suffix, splitting subwords of PhrasesLikeThis with underscores, and lower-casing it, like so: phrases_like_this.

Types of Commands
You can create the following types of commands:
Window commands (sublime_plugin.WindowCommand)
Text commands (sublime_plugin.TextCommand)

CloneBelow ia a Window command
It should be called with “clone_below”

In Preferences -> Key Bindings

{ “keys”: [“ctrl+shift+d”], “command”: “duplicate_line” },
I chose to Override that with:
{ “keys”: [“ctrl+shift+d”], “command”: “clone_below” },

–> Creates new pane, doesn’t split file…

View -> Origami -> Pane -> Create -> Below works, as does Destroy
View -> Origami -> File -> CloneTo -> Below (with the empty pane already) splits the empty pane below and puts Untitled in the lower half
View -> Origami -> File -> CloneTo -> Below (without an empty pane already) creates the pane and clones the existing file to it!

Commenting the “create_pane” line in the CloneBelowCommand makes it work!

0 Likes