Sublime Forum

Where should I be storing custom layouts?

#1

Hey all,

Having pieced together infos from this forum and elsewhere, I found how to create a custom 3-pane layout (gist.github.com/1320281).

The thing is, I’m not sure where I should be keeping this layout. It appears that layouts are defined twice — once in Packages/Default/Main.sublime-menu and again in Packages/Default/Default (PLATFORM).sublime-keymap.

Both of the above referenced files get blown away upon update. Where should I be putting my custom layout that I can assign a keymap to it and not lose it upon upgrade?

0 Likes

#2

Create the file Packages/User/Main.sublime-menu

0 Likes

#3

OK, that raises a few questions:

Do I need to copy the entire file, or is there a way to include just my addition? The point is that updates shouldn’t get screwed by the copied Packages/User/Main.sublime-menu from this version.

Do I also need to copy Default (PLAT).sublime-keymap?

Is it even necessary to define the layout twice? Main.sublime-menu has the caption and Default (OSX).sublime-keymap has the keys definition, but the rest is duplicate data. What’s the canonical source here?

If there is some documentation on the matter, I’d appreciate being pointed in its direction—haven’t succeeded in finding it so far.

0 Likes

#4

Create an empty Packages/User/Main.sublime-menu file
Copy your code/layout into it, no need to duplicate
The global files are read first, the user files last. User file overwrites.

I put a 2 columns, 1 Row Layout into Packages/User/Main.sublime-menu file, which looks this now (only this code is in my file. This is not an excerpt):

{
"id": "view",
"children": {
    "id": "layout",
    "children": {
       "command": "set_layout",
       "caption" : "2C - 1R",
       "mnemonic": "J",
       "args":
       {
          "cols": [0.0, 0.5, 1.0],
          "rows": [0.0, 0.5, 1.0],
          "cells":
          
             [0, 0, 1, 1], [1, 0, 2, 1],
             [0, 1, 2, 2]
          ]
       }
    }]
}]}]

Btw the files are read instant, no need to reopen sublime text2.

I got my information on this board, different websites, the documentation, etc.
I have no idea what (PLAT).sublime-keymap does and i guess thats the basis/canonical file which is read before the “General/Default” file.

If you insert an already existing layout, it is overwritten (I did not test this). If you add a layout with a different name (like i did) it is added to the menu.

Hope this clears things a bit up.

0 Likes

#5

Thanks Stefan — this was very helpful!

Some testing reveals that the keymap doesn’t seem to work without the corresponding layout, and the layout definition must be identical or the keymap won’t be applied.

In other words, if you wan to have a layout and have a keybinding for it, you have to copy the same layout in both Main.sublime-menu and Default (OSX).sublime-keymap.

One last question – what the purpose of the ‘mnemonic’ argument?

0 Likes

#6

For posterity, I’ve posted my finished settings here: gist.github.com/1320281

0 Likes