How to open file in keymap?


#1

Hey, I want to open a specific file from project with shortcut. How can i do that in atom is there a package.For example I use advance-open-file is great but i want to open with shortcut.


#2

You can do anything with the init.coffee file and Atom’s API. Opening files is easy and straightforward. To be clear: you want to open a specific file that’s never going to change?


#3

Yes i use laravel and sometime i have the same names for files.I just want to put the files somewere with a shortcut and when i press the desire shortcut to open the files in atom.


#4

Add the following to your init.coffee (File > Init Script…)

atom.commands.add 'atom-text-editor',
  'open:master-blade': (event) ->
    atom.workspace.open('path/to/master.blade.php')

Then add the following to keymap.cson (File > Keymap…)

'.editor:not(.mini)':
  'ctrl+1': 'open:master-blade'

#7

atom.commands.add ‘atom-text-editor’,
‘open:master-blade’: (event) ->
atom.workspace.open(‘C:\Users\Adrian\Documents\Projects\lara\panel\resources\views\master.blade.php’)

‘.editor:not(.mini)’:
‘ctrl+1’: ‘open:master-blade’

It dosent open the files is the path correct write ?


#8

It should work fine with absolute paths, but it’s hard to tell whether there’s a problem in your syntax. Please use the </> button in the editor to format your code. Otherwise the indentation is lost and your quotes are transformed.


#9

Hello Adrian.

Please try the following modifications ->

### init.coffee ###
atom.commands.add 'atom-text-editor',
  'open:master-blade': (event) ->
    atom.workspace.open('C:/Users/Adrian/Documents/Projects/lara/panel/resources/views/master.blade.php')
### keymap.cson ###
'atom-text-editor:not(.mini)':
  'ctrl-1': 'open:master-blade'

Regards.


#10

Hey i put the code like you say. In Key Binding Resolver it’s shows open:master-blade, but it dosent open the file :(.


#11

It work’s now my bad needed restart Thanks so much guys was lookink for this!!. Hope someone makes a package for this!


#12

That is good news Adrian.

Interesting comment. What @idleberg (thank you) designed for you is specifically custom and too trivial for a package in my opinion. Or do you have an extended functionality in mind?


#13

I was thinking to make a package like so. The user will have some field for the name of the file to open and another for the shortcut. Or when I access a file will enter a shortcut and a popup box will appear to enter the shortcut for that file and save.

Yeah is a little trivial but in my ideea if you work a long time for a project and have all the time same names for some files you can open the main one fast. Why i asked because I hate working with lot’s of tabs and sometime I close some of them then i need them back lol.I use advanced-open-file greate package.


#14

There are packages that assist with project management and the management of tabs.

If you are wanting to develop a package you can have a look at the flight manual:
https://flight-manual.atom.io/hacking-atom/sections/package-word-count
https://flight-manual.atom.io/hacking-atom/sections/package-modifying-text
https://flight-manual.atom.io/hacking-atom/sections/package-active-editor-info

~