Sublime Forum

How does clone command work?

#1

Dear admin,

I would like to create some plugin that would do what clone commands does right now, that is, create an exact copy of a buffer, and any change in one view will be reflected in the other.

Therefore I would like to know how that command works, how I could call it from the console, and how to use it in my plugin? It looks like it is part of the closed source part of Sublime.

0 Likes

#2

Try this:

window.runCommand("clone")

Commands reference: sublimetext.com/docs/commands

0 Likes

#3

[quote=“gpfsmurf”]Try this:

window.runCommand("clone")

Commands reference: sublimetext.com/docs/commands[/quote]

Awesome. How could I have missed that?

Now I know how to call that command, is there anyway we could control how it behaves? For example, I don’t want to clone the buffer to another view, but instead store it into a variable and create a view later, on another instance of Sublime.

0 Likes

#4

You could store the filename in a variable, and then use the ‘open’ command later.

0 Likes

#5

But will the file opened by “open” command has the features of cloning? Like changes in one view is reflected in the other view?

0 Likes

#6

Actually no, I just tested it.

If you open a file which is already open in the current window, it will switch to that tab instead.
If you open a file which is open in a different window, it will open it, but changes won’t be reflected in the other window.

So I don’t know of a way to clone a view in a *new *sublime window. It looks like it only works in the same window… But it’s still quite handy with double panes.

0 Likes

#7

Yeah, I have dual-monitor, so having two windows of Sublime on each monitor each would come in handy. If I could know how the clone works, I could reuse it to make a simple plugin that allows what I want.

0 Likes