Kurt Peek
Kurt Peek

Reputation: 57471

How to define 'previous file' and 'next file' shortcut keys in Sublime Text 3?

I'm trying to implement 'Next File' and 'Previous File' shortcuts in Sublime Text 3 following this answer, Change "Next File" and "Previous File" shortcut in Sublime Text 2.

However, I'm unable to find the "Key Bindings - User" file mentioned in that answer. I can find some .sublime-keymap files in ~/Library/Application Support/Sublime Text 3/Packages, but they seem to be specific to certain installed packages:

~/L/A/S/Packages> find . -name '*keymap*'
./pymdownx/st3/pymdownx/keymap_db.py
./Pretty JSON/Default (Windows).sublime-keymap
./Pretty JSON/Default (OSX).sublime-keymap
./Pretty JSON/Default (Linux).sublime-keymap
./Babel/Default.sublime-keymap

Where would be the right place to add these commands?

[
  { "keys": ["ctrl+]"], "command": "next_view" },
  { "keys": ["ctrl+["], "command": "prev_view" }
]

Incidentally, the next_view and prev_view commands are described at https://docs.sublimetext.io/reference/commands.html.

Upvotes: 1

Views: 321

Answers (1)

OdatNurd
OdatNurd

Reputation: 22791

See the answer I added in your other question regarding why you can't find the files that the documentation is pointing to.

Regarding how many of the resource files in Sublime Text work, when Sublime loads them it gathers all of the files with the same name across all of the packages you have installed and combines them together. This merging happens in a very specific order related to the name of the package that the files are in to ensure consistent results. Generally speaking, the package list is sorted lexically by name and files are merged in that order, except that Default always comes first and User always comes last.

This allows Sublime to provide the default bindings in the Default package, any package can include their own bindings that augment the list, and the User package (where all of your user specific customizations go) is the "final arbiter".

In this case, the default key bindings for your platform are stored in the Default (<platform>).sublime-keymap file in the Default package, and your user customized key bindings are in a file of the same name in your User package.

The Preferences > Key Bindings menu item opens the appropriate files in a split window, with the platform defaults on the left and your user customizations (if any) on the right.

It's also worth noting that in previous versions of Sublime Text, the menu items for editing things such as key bindings existed as multiple items, so you would see things like Preferences > Key Bindings - Default and Preferences > Key Bindings - User. In this case, one menu item opens the defaults for your platform and the other opens your user file.

Some packages still present their settings in this manner and some have switched to the new format, so this is still something that you see from time to time. In cases like this, you can pick the single menu item to refer to either of the older style menu items. It's essentially doing both of them for you at the same time.

Upvotes: 1

Related Questions