Bind to ctrl-x-left/right/up/down


#1

Hi,

I want to bind window:focus-pane-above to ctrl-x-up and so forth.

How can I achieve this?

For Frodo
Daniel


#2

For panel navigation, have this in my keymap.cson file. I use the same bindings I’m using on emacs and tmux, so I’d like to keep them tidy.

'atom-workspace atom-text-editor:not([mini])':
  'ctrl-a |': 'pane:split-right'
  'ctrl-a _': 'pane:split-down'
  'ctrl-a right': 'window:focus-pane-on-right'
  'ctrl-a left': 'window:focus-pane-on-left'
  'ctrl-a up': 'window:focus-pane-above'
  'ctrl-a down': 'window:focus-pane-below'

#3

That is nice.

I was using Hydra in emacs. Is there a similar way like holding down ctrl-a and press left n times to move n times to the left.?


#4

I think this has to be programmed to be achieved. I developed once a mechanism to check whether the ctrl key was held down. It was something like this:

# inside your command
atom.workspace.observeTextEditors (editor) ->
  view = atom.views.getView editor

  view.onkeydown = (event) ->
    if event.keyCode is 17 then @ctrlPressed = true

  view.onkeyup = (event) ->
    if event.keyCode is 17 then @ctrPressed = false

You can leverage this hack to check if the user is holding the ctrl key down. Put it in your init.coffee file, so a specific behavior will be activated when you key is pressed.

Enjoy Atoming!

Edit: BTW, in my keymap.cson file I also have some keys to navigate, in particular to move to the beginning/end of the word.

'atom-workspace atom-text-editor:not([mini])':
  'escape k': 'editor:delete-line'
  'escape left': 'editor:move-to-beginning-of-word'
  'escape right': 'editor:move-to-end-of-word'
  'escape backspace': 'editor:delete-to-beginning-of-word'
  'escape up': 'editor:fold-current-row'
  'escape down': 'editor:unfold-current-row'
  'ctrl-a |': 'pane:split-right'
  'ctrl-a _': 'pane:split-down'
  'ctrl-a right': 'window:focus-pane-on-right'
  'ctrl-a left': 'window:focus-pane-on-left'
  'ctrl-a up': 'window:focus-pane-above'
  'ctrl-a down': 'window:focus-pane-below'
  'ctrl-i': 'editor:auto-indent'
  'ctrl-alt-m': 'atom-math:evaluate'
  'ctrl-up': 'atom-math:getPreviousHistoryCommand'
  'ctrl-down': 'atom-math:getNextHistoryCommand'

#5

Thanks for this reply.

Since I am new to Atom I do not really know how this affects my keymaps. How do I use a custom function like this.


#6

I’m not sure about it.
Usually, if you have to add a new functionality to Atom, you can:

  • add a custom command into your init.coffee file and then call it from the command palette or with a custom binding in the keymap.cson file, or
  • build a package

What you should do depends on the feature degree of complexity. A script in the init file is limited and cannot leverage on npm packages. A package is more complex and will probably take you a little time to get it working as required.