Platformio-atom-ide-terminal: Keyboard shortcut to switch between terminal & code editor

Created on 28 Jul 2016  路  27Comments  路  Source: platformio/platformio-atom-ide-terminal

#97 for terminal-plus, seems not be implemented yet. I think this would be a very helpful feature.

Most helpful comment

Thanks for the comments of @jlerche @cachance7 and @laubblatt, I would like to summarize a working solution without change the code inside plugin.

  1. Add the following code into Atom's Init Script init.coffee, you can open it from menu or command palette.
    coffee atom.packages.onDidActivatePackage (pack) -> if pack.name == 'platformio-ide-terminal' atom.commands.add 'atom-workspace', 'editor:focus-main', -> p = atom.workspace.getActivePane() panels = atom.workspace.getBottomPanels() term = panels.find (pan) -> pan.item.constructor.name == 'PlatformIOTerminalView' and pan.visible if not term # Open a new terminal editor = atom.workspace.getActiveTextEditor() atom.commands.dispatch(atom.views.getView(editor), 'platformio-ide-terminal:new') else if term and p.focused isnt false term.item.focus() else if term and p.focused is false term.item.blur() # Stops the terminal from blinking p.activate()
  2. Add your keyboard shortcut into Atom's Keymap keymap.cson, you can also open it from menu or command palette. An example here, you can change to whatever combination you like.
    'atom-workspace': 'ctrl-;': 'editor:focus-main'
  3. Reload Atom and enjoy! 馃帀

P.S. Anyone who knows how to integrate these into the plugin could make a pull request to free others from hacking like this.

All 27 comments

I agree. I hope this feature will be added soon.

+1

+1

:+1

Here is a simple example to make up your custom keyboard bindings to toggle between the editor and the terminal. Put this in your keymap.cson file

The following helps show/hide the terminal using Ctrl Dot as the keybinding

'.platform-darwin atom-workspace':
  'ctrl-.':'platformio-ide-terminal:toggle'

The following helps navigate between tabs within the terminal.

'.platformio-ide-terminal':
  'ctrl-cmd-p': 'platformio-ide-terminal:prev'
  'ctrl-cmd-n': 'platformio-ide-terminal:next'

See the attached screenshot for other commands you can customize.

screen shot 2016-09-25 at 8 59 05 am

Just realized, the above only helps with opening and closing the terminal and doesn't help with switching focus. But the above ^^^ can be used as a work around until we have real focus switch support in the ide terminal.

Hacky way to toggle between terminal and active editor pane (wrote this for terminal plus, should be easy to adapt)

in init.coffee

atom.commands.add 'atom-workspace',
   'editor:focus-main', ->
       p = atom.workspace.getActivePane()
       term = null
       #p.activate()
       panels = atom.workspace.getBottomPanels()
       for pan in panels
           if pan.item.constructor.name == 'TerminalPlusView'
               term = pan.item
               break
        if term and p.focused isnt false
            term.focus()
        else if term and p.focused is false
            p.activate()

I am new to Atom, what of the above code of jlerche I should change?
What would be the key binding in the keymap.cson?
Any help appreciated!

@jlerche That was a great starting point. Here's how I ultimately adapted mine:

 atom.packages.onDidActivatePackage (pack) ->
  if pack.name == 'platformio-ide-terminal'
    atom.commands.add 'atom-workspace',
      'editor:focus-main', ->
        p = atom.workspace.getActivePane()
        panels = atom.workspace.getBottomPanels()
        term = panels.find (pan) ->
          pan.item.constructor.name == 'PlatformIOTerminalView' and pan.visible
        if not term
          # Open a new terminal
          editor = atom.workspace.getActiveTextEditor()
          atom.commands.dispatch(atom.views.getView(editor), 'platformio-ide-terminal:new')
        else if term and p.focused isnt false
          term.item.focus()
        else if term and p.focused is false
          term.item.blur()  # Stops the terminal from blinking
          p.activate()

(Edit: updated to be specific about how this is loading)

@laubblatt You can use anything you want. Here's what I added to the end of platformio-ide-terminal.cson in order to use ctrl-; for my setup.

'atom-workspace':
  'ctrl-;': 'editor:focus-main'

Hi Casey! great it works now for me - also the edit for the keymap.cson was very helpful!

Thanks for the comments of @jlerche @cachance7 and @laubblatt, I would like to summarize a working solution without change the code inside plugin.

  1. Add the following code into Atom's Init Script init.coffee, you can open it from menu or command palette.
    coffee atom.packages.onDidActivatePackage (pack) -> if pack.name == 'platformio-ide-terminal' atom.commands.add 'atom-workspace', 'editor:focus-main', -> p = atom.workspace.getActivePane() panels = atom.workspace.getBottomPanels() term = panels.find (pan) -> pan.item.constructor.name == 'PlatformIOTerminalView' and pan.visible if not term # Open a new terminal editor = atom.workspace.getActiveTextEditor() atom.commands.dispatch(atom.views.getView(editor), 'platformio-ide-terminal:new') else if term and p.focused isnt false term.item.focus() else if term and p.focused is false term.item.blur() # Stops the terminal from blinking p.activate()
  2. Add your keyboard shortcut into Atom's Keymap keymap.cson, you can also open it from menu or command palette. An example here, you can change to whatever combination you like.
    'atom-workspace': 'ctrl-;': 'editor:focus-main'
  3. Reload Atom and enjoy! 馃帀

P.S. Anyone who knows how to integrate these into the plugin could make a pull request to free others from hacking like this.

@YujiShen, @jlerche, @cachance7 and @laubblatt , could you provide PR for this issue? Thanks!

Hi! I have a question about the @YujiShen compact solution. I can't seem to get it to work properly. First two 'if's work fine, creating new terminal window if there is none and switching from text editor to terminal but if terminal is currently active window it doesn't switch back to text editor.

Any thoughts? Using Ubuntu 14.04 and atom 1.13.1 x64

UPDATE: discovered that above code won't work for me when using 'ctrl-something' shortcuts (clash with terminal commands?). Changing to 'alt-y' shortcut works perfectly.

Hello, can someone help me with this solution?
I copied @YujiShen 's code but I am getting Failed to load {path}/init.coffee pack is not defined.
I am using platformio-ide-terminal 2.2
and in the script the name of the pack is platformio-ide-terminal. I dont understand why I am getting this error.

I am using Atom 1.13.1
Thank you!

edited: to correct typo to avoid confusion

@andreikoenig where did you paste the code? That is a weird error since actual file is called init.coffee. Try pasting the code meant for init.coffee through atom interface, by going to Edit -> Init Script... then save, restart atom, give it a go

Ugh, sorry had to delete my comment.
@hbrezak , thank you for taking your time to answer! It was a typo in my message above. I did paste it into the init.coffee.

here is my init.coffee screenshot http://i.imgur.com/TEPnkAZ.png
and here is the error I am getting when I reload Atom. http://i.imgur.com/P2KIy4h.png

Thank you!

I believe line 16 of your init.coffee file was meant to be a comment but you forgot to put # before the word 'switch'

@hbrezak , yes! I caught it after I posted the reply! (embarrassing). I updated my comment, please see updated screenshots above. That was not an issue. I made a mistake commenting that block back in to make a screenshot. :(

Okay, something also went wrong with indentation during copy/paste, your line 18 is not properly indented and probably all the lines after it. Your problem should be resolved once you fix that

@hbrezak , oh man, thank you so much! That was it. Double embarrassing. I have been coding in Ruby for about a year, and it is so weird when indentation matters, I never thought to check that! Thanks again!

Hm, the PR #183 implemented a focus command
'platformio-ide-terminal:focus': => @activeTerminal.focusTerminal()

But that's missing the _unfocus_ part which is equally important to toggle back to the last editor pane.

Could this issue be re-opened for the time being?

@colin-kiegel implemented un-focus in PR #218

One alternative after close platformio-terminal is use the command ALT+\ (get focus of Tree View), then ALT+\ again (or Left Arrow key with one pane).
System: fedora 29 Workstation (Gnome desktop) , Linux.

Nice workaround, @christianbueno1. Could have sworn I had this working with

  'ctrl-t': 'platformio-ide-terminal:focus'
  'ctrl-alt t': 'editor:focus-main'

but when I went to check one more time before sending, it didn't work. Maybe I'm going crazy.

Thanks @the-j0k3r. I just noticed that ctrl-alt-f does indeed focus on the terminal and back to the editor as you repeatedly press it. My Ctrl+t keymap will also get me down to the terminal, just not back to the editor! I suppose I can live with ctrl-alt-f.

Was this page helpful?
0 / 5 - 0 ratings