Sublime Forum

Want keystroke for "New view into file"

#1

I’m not pythonian, so I can’t just study the source available.

The menu item “FILE/New View into file” has no keystroke, and I don’t even know where to look to find the function to bind to the keystroke.

I really want: “New view into file and put the second view in another row, making the row if needed.

I can guess that maybe some existing package has this, but there is no way to search for it.

Any hints will be appreciated.

RickyS

0 Likes

#2

If you find a command that it has no keymap, you can do the following (on windows, but on other platforms should be similar):

  1. go to where you installed Sublime
  2. Open the Packages folder
  3. Open the Default.sublime-package file (it’s just an archive, so you can open it with any zip utility)
  4. Search for Main.sublime-menu and open it into Sublime
  5. You will see that new view into file is defined like:
{ "command": "clone_file", "caption": "New View into File", "mnemonic": "e" },

So the command you are looking for is “clone file”. Tadaaa!

Next step is very simple, just add a new keymap:

{ "keys": "ctrl+shift+n"], "command": "clone_file" }

And you are good to go :smile:

0 Likes

#3

Another route to determine what command gets run when you do something is to enable logging:

  1. Open the console (view -> Show Console)

  2. Type: sublime.log_commands(True)

  3. Do something to see what command gets run (it will be displayed in the console).

  4. In the console, type sublime.log_commands(False) to turn off logging.

Since you asked for multiple steps, here’s a simple plugin that should get you started.

import sublime, sublime_plugin

class SampleCommand(sublime_plugin.WindowCommand):

    def run(self):
        view = self.window.active_view()
        self.window.run_command('clone_file')
        self.window.run_command('set_layout', args={"cells": [0, 0, 1, 1], [0, 1, 1, 2]], "cols": [0.0, 1.0], "rows": [0.0, 0.5, 1.0]})
        self.window.set_view_index(view, 1, 0)
0 Likes