Keybindings to the Sidebar's "Add file"


Whenever a new file is created with cmd + n, a new tab is created and saving it causes a save dialog to appear. You can see a gif screencast here.

I’ve been looking for a keybinding for the sidebar’s add file so I can replace cmd + n with this so I can directly create files without going through all the extra keystrokes. It’s sorta like the Advanced New File plugin with sublime.

Thanks. :smile:


The command is tree-view:add-file, but I’ve tried creating a global keymap for it and it doesn’t work. (At least the last time I tried it.) I suspect that there is some information in the tree view that it needs to do its job that it doesn’t get when the tree view isn’t focused.

You could take a look at the Tree View package and see what they’re doing …


I’ve also tried creating a key binding for the “Add File” command with no luck. Can anyone with a bit more knowledge of Atom explain why this isn’t working?

  'ctrl-cmd-a': 'tree-view:add-file'


Because the event is only being listened for on the tree view DOM element,

So if it is triggered on the editor (which it will be in your case since the selector is on `.editor), it will bubble up the DOM but never hit the tree view element since it isn’t a parent of the editor view.

I would consider this a bug, would you mind opening this up as an issue on the tree view repo?


So should that command be defined as core? I’m trying to get an understanding of how Atom works.


Well, for now, is it possible to bind multiple actions to a key? For example, I want to bind cmd-n to tree view focus then tree view new file just to simulate that action I guess.


You could create your own command that performed both actions and then bind that command to a key. I’m pretty sure @AbeEstrada has a way to do this, create commands that is, from the init script even.


Try this:

  'cmd-n': 'tree-view:add-file'


Thanks! Worked like a charm. :slight_smile: