The buffer is the data of a opened file or yet to create file. Usually for each view there is just one buffer. when two views shares the same buffer, that is a “cloned view” (any changes you do in one view will be shown in the other view, regardless if the file was saved or not). When you open a file twice (without cloning) you have two buffers, if you change these two views independently, you risk to overwrite the changes made into the other view.
An easy way to see a buffer in action.
- Mainmenubar - view – layout - columns 2
- CTRL+SHIFT+P, then search for “new view into file” (this is a poor named command that should be called “clone view”)
- Now drag the tab to the second column
- type anything in any of the two tabs.
- Anything you type should be shown in both views because these share the same buffer.
Some applications for this feature, if you have a really big screen, you may want to show more lines of the same file in columns syncing the scrolling, anything you write in any of the three columns will appear in other columns because these share the buffer.
You almost never want two buffers for a same file, because that leads to data lost when saving. Thats why I created https://github.com/titoBouzout/PreventFakeClones which is trying to detect when you open the same file in two instances and then closes any duplicated, and clones the first view getting the same buffer for all the views involved.
BUG 1: Theres a bug in ST with the use of clones. When you run a command or use on_activated(on_something), you always get as “view” parameter the first view, even if the view was the third view of this cloned file. For this reason I almost always use sublime.active_window().active_view() instead of self.view.
BUG 2: There two views will share the settings object.
BUG 3: You cannot move a cloned view to other windows.
BUG N: I cannot remember
Or something in these lines