How to remap ctrl-k


#1

Hi.

I’m trying to reproduce my vim environment into atom, and till now it’s working well but I still have a problem to remap ctrl-k to focus-pane-above:
This key being a prefix key by default (Why?) a simple …

'ctrl-k ': 'window:focus-pane-above'

… won’t work as expected.

I’ve tried to unbind all ctrl-k shortcuts but still no result.

Any idea?

Here is my keymap.cson:

# General keybindings
'atom-workspace':

  # Core
  'ctrl-n': 'core:move-down'
  'ctrl-p': 'core:move-up'

  # The following keybindings are remaped to 'native' in ex & vim insert mode
  # (1)
  ', ,': 'command-palette:toggle'
  ', f': 'fuzzy-finder:toggle-file-finder'
  ', b': 'fuzzy-finder:toggle-buffer-finder'
  ', l': 'go-to-line:toggle'
  ', g': 'git-plus:menu'
  ', N': 'tree-view:toggle'
  ', n': 'tree-view:toggle-focus'

  # Plugins
  'alt-c': 'color-picker:open'
  'alt-p': 'clipboard-plus:toggle'
  'ctrl-shift-n': 'application:new-file'
  'f8': 'source-preview:toggle'
  'f9': 'script:run'
  'ctrl-f9': 'script:close-view'
  ', e': 'linter:togglePanel'

# #################
# Plugins
# #################

# Emmet
'atom-text-editor[data-grammar="text html basic"]:not([mini]), atom-text-editor[data-grammar~="jade"]:not([mini]), atom-text-editor[data-grammar~="css"]:not([mini]), atom-text-editor[data-grammar~="sass"]:not([mini])':
  'tab': 'emmet:expand-abbreviation-with-tab'

# ###############################
# Vim-mode & plugins in vim-mode
# ###############################

# Not insert-mode
# ################
'atom-text-editor.vim-mode:not(.insert-mode)':

  # Symbols view
  ', s': 'symbols-view:toggle-file-symbols'

  # Cursor history
  'ctrl-i': 'cursor-history:next'
  'ctrl-o': 'cursor-history:prev'

  # Multi cursor
  'alt-k': 'multi-cursor:expandUp'
  'alt-j': 'multi-cursor:expandDown'

  # Terminal panel
  'g o t': 'terminal-panel:toggle'

  # Symbols tree view
  ', t': 'symbols-tree-view:toggle'

  # Git diff
  'g n': 'git-diff:move-to-next-diff'
  'g p': 'git-diff:move-to-previous-diff'

  # Clipboard plus
  ', p': 'clipboard-plus:toggle'

  # For windows, tabs & panes
  'shift-h': 'pane:show-previous-item'
  'shift-l': 'pane:show-next-item'
  'shift-q': 'core:close'
  'f6': 'tabs:close-all-tabs'
  'g s o': 'custom:close-other-panes'
  'g s s': 'pane:split-down'
  'g s v': 'pane:split-right'
  'g s q': 'pane:close'
  'g s o': 'pane:close-other-items'
  'ctrl-j': 'window:focus-pane-below'
  # 'ctrl-k ': 'window:focus-pane-above'
  'ctrl-h': 'window:focus-pane-on-left'
  'ctrl-l': 'window:focus-pane-on-right'

  # For bookmarks
  ', m': 'bookmarks:view-all'
  'm m': 'bookmarks:toggle-bookmark'
  'm space': 'bookmarks:clear-bookmarks'

  # Remap default vim-mode keybindings
    # ^ is not working in azerty layout
  'å': 'vim-mode:move-to-first-character-of-line'

  # Various & general keybindings for text editing
  'g c': 'editor:toggle-line-comments'
  'shift-alt-k': 'editor:move-line-up'
  'shift-alt-j': 'editor:move-line-down'
  'ctrl-f': 'find-and-replace:show'
  'ctrl-shift-f': 'project-find:show'
  'ctrl-d': 'find-and-replace:select-next'

# Tree view
# ################
'.tree-view':
  'd d': 'tree-view:remove'
  'y': 'tree-view:copy'
  'p': 'tree-view:paste'
  'x': 'tree-view:cut'
  'a f': 'tree-view:add-file'
  'a d': 'tree-view:add-folder'
  's': 'tree-view:open-selected-entry-down'
  'v': 'tree-view:open-selected-entry-right'

# Visual-mode
# ################

'atom-text-editor.vim-mode.visual-mode':
  'enter': 'atom-alignment:alignMultiple'
#   'k': 'exit-insert-mode-if-proceded-by-j'

# Insert-mode
# ################
'atom-text-editor.vim-mode.insert-mode':
  'k': 'exit-ins-mode-if-proceded-by-j'
  'alt-d': 'editor:duplicate-lines'
  'ctrl-tab': 'snippets:available'

  # Normal behavior for some mapped keybindings (1)
  ',': 'native!'
  '!': 'native!'
  'space': 'native!'

#2

Looks like the problem is not related to atom, this is very strange but Ctrl-k is not working anymore on my system (Xubuntu 14.04.2) :confused:

I’ll try to find why, so please don’t close the discussion yet,


UPDATE:

I’ve solved it, the problem was coming effectively from my system.


UPDATE 2:

Now that atom detects correctly Ctrl-k, I still can not bind it to window:focus-pane-above.
So the main problem of this discussion is still present.

Need help!


#3

You can open the keybinding resolver (with ctrl-.) to see which command atom dispatches when you press ctrl-k. It will also give you the selector for that keybinding. Make sure the selector you use in your keymap.cson has a higher specificity than the selector for the other commands.


#4

Ctrl-k is used by default as a prefix key, so the keybinding resolver as expected gives me all the ctrl-k shortcuts (And there is a lot :smile:).

So should I unbind all of them (unset) to get only one command to work?


#5

Aha! Does it work if you press ctrl-k and just wait for about a second? The delay can be quite long for prefix keys… If you really want ctrl-k to do something else, and not have to wait such a long time, then yeah, unset!ting them all is your only option…


#6

No, it doesn’t work.

Ok, I’ve unset!ed all of them (I think so) but they still appear in the keybinding resolver :neutral_face:

My keymap.cson:

# Unset all ctrl-k keybindings
'body':
  'ctrl-k ctrl-alt-w': 'unset!'
  'ctrl-k ctrl-down': 'unset!'
  'ctrl-k ctrl-left': 'unset!'
  'ctrl-k ctrl-right': 'unset!'
  'ctrl-k ctrl-n': 'unset!'
  'ctrl-k ctrl-p': 'unset!'
  'ctrl-k ctrl-w': 'unset!'
  'ctrl-k down': 'unset!'
  'ctrl-k left': 'unset!'
  'ctrl-k right': 'unset!'
  'ctrl-k up': 'unset!'
'atom-workspace atom-text-editor:not([mini])':
  'ctrl-k ctrl-0': 'unset!'
  'ctrl-k ctrl-1': 'unset!'
  'ctrl-k ctrl-2': 'unset!'
  'ctrl-k ctrl-3': 'unset!'
  'ctrl-k ctrl-4': 'unset!'
  'ctrl-k ctrl-5': 'unset!'
  'ctrl-k ctrl-6': 'unset!'
  'ctrl-k ctrl-7': 'unset!'
  'ctrl-k ctrl-8': 'unset!'
  'ctrl-k ctrl-9': 'unset!'
'.platform-win32, .platform-linux':
  'ctrl-k ctrl-b': 'unset!'
'.platform-win32 atom-text-editor, .platform-linux atom-text-editor':
  'ctrl-k ctrl-d': 'unset!'
'atom-workspace atom-text-editor':
  'ctrl-k ctrl-l': 'unset!'
  'ctrl-k ctrl-u': 'unset!'
'.platform-win32 .tree-view, .platform-linux .tree-view':
  'ctrl-k down': 'unset!'
  'ctrl-k up': 'unset!'
  'ctrl-k right': 'unset!'
  'ctrl-k left': 'unset!'
  'ctrl-k h': 'unset!'
  'ctrl-k j': 'unset!'
  'ctrl-k k': 'unset!'
  'ctrl-k l': 'unset!'

# General keybindings
'atom-workspace':

  # Core
  'ctrl-n': 'core:move-down'
  'ctrl-p': 'core:move-up'

  # The following keybindings are remaped to 'native' in ex & vim insert mode
  # (1)
  ', ,': 'command-palette:toggle'
  ', f': 'fuzzy-finder:toggle-file-finder'
  ', b': 'fuzzy-finder:toggle-buffer-finder'
  ', l': 'go-to-line:toggle'
  ', g': 'git-plus:menu'
  ', N': 'tree-view:toggle'
  ', n': 'tree-view:toggle-focus'

  # Plugins
  'alt-c': 'color-picker:open'
  'alt-p': 'clipboard-plus:toggle'
  'ctrl-shift-n': 'application:new-file'
  'f8': 'source-preview:toggle'
  'f9': 'script:run'
  'ctrl-f9': 'script:close-view'
  ', e': 'linter:togglePanel'

# #################
# Plugins
# #################

# Tree view
'.tree-view':
  'd d': 'tree-view:remove'
  'y': 'tree-view:copy'
  'p': 'tree-view:paste'
  'x': 'tree-view:cut'
  'a f': 'tree-view:add-file'
  'a d': 'tree-view:add-folder'
  's': 'tree-view:open-selected-entry-down'
  'v': 'tree-view:open-selected-entry-right'


# ###############################
# Vim-mode & plugins in vim-mode
# ###############################

# Not insert-mode
# ################
'atom-text-editor.vim-mode:not(.insert-mode)':

  # Symbols view
  ', s': 'symbols-view:toggle-file-symbols'

  # Cursor history
  'ctrl-i': 'cursor-history:next'
  'ctrl-o': 'cursor-history:prev'

  # Multi cursor
  'alt-k': 'multi-cursor:expandUp'
  'alt-j': 'multi-cursor:expandDown'

  # Terminal panel
  'g o t': 'terminal-panel:toggle'

  # Symbols tree view
  ', t': 'symbols-tree-view:toggle'

  # Git diff
  'g n': 'git-diff:move-to-next-diff'
  'g p': 'git-diff:move-to-previous-diff'

  # Clipboard plus
  ', p': 'clipboard-plus:toggle'

  # For windows, tabs & panes
  'shift-h': 'pane:show-previous-item'
  'shift-l': 'pane:show-next-item'
  'shift-q': 'core:close'
  'f6': 'tabs:close-all-tabs'
  'g s o': 'custom:close-other-panes'
  'g s s': 'pane:split-down'
  'g s v': 'pane:split-right'
  'g s q': 'pane:close'
  'g s o': 'pane:close-other-items'
  'ctrl-j': 'window:focus-pane-below'
  'ctrl-k ': 'window:focus-pane-above'
  'ctrl-h': 'window:focus-pane-on-left'
  'ctrl-l': 'window:focus-pane-on-right'

  # For bookmarks
  ', m': 'bookmarks:view-all'
  'm m': 'bookmarks:toggle-bookmark'
  'm space': 'bookmarks:clear-bookmarks'

  # Remap default vim-mode keybindings
    # ^ is not working in azerty layout
  'å': 'vim-mode:move-to-first-character-of-line'

  # Various & general keybindings for text editing
  'g c': 'editor:toggle-line-comments'
  'shift-alt-k': 'editor:move-line-up'
  'shift-alt-j': 'editor:move-line-down'
  'ctrl-f': 'find-and-replace:show'
  'ctrl-shift-f': 'project-find:show'
  'ctrl-d': 'find-and-replace:select-next'

# Visual-mode
# ################

'atom-text-editor.vim-mode.visual-mode':
  'enter': 'atom-alignment:alignMultiple'

# Insert-mode
# ################
'atom-text-editor.vim-mode.insert-mode':
  'k': 'exit-ins-mode-if-proceded-by-j'
  'alt-d': 'editor:duplicate-lines'
  'ctrl-tab': 'snippets:available'
  'j': 'expand-emmet-if-proceded-by-h'

  # Normal behavior for some mapped keybindings (1)
  ',': 'native!'
  '!': 'native!'
  'space': 'native!'

So, can I throw away my computer now? :grimacing:


#7

No, now your specificity is too low again. Most of the ctrl-k keybindings use the atom-workspace atom-text-editor:not([mini]). In general, you’ll want to override the same selector as the key is bound to if you’re unset!ting keybindings.


#8

Sorry but I didn’t get you (English is not my native language).

I want to assign to Ctrl-k the command ‘window:focus-pane-above’ in atom-text-editor.vim-mode:not(.insert-mode) selector(s), so In which selector should I unset Ctrl-k?

Thanks for your time.


#9

Well, if you check the image you posted, you see in the leftmost column the command, and in the third column the selector it is applied to; the editor:upper-case command is applied to the atom-workspace atom-text-editor command and editor:unfold-all to atom-workspace atom-text-editor:not([mini]). So in order to unset those commands, you would have in your keymap.cson

'atom-workspace atom-text-editor':
  'ctrl-k ctrl-u': 'unset!'

'atom-workspace atom-text-editor:not([mini])':
  'ctrl-k ctrl-0': 'unset!'

And now you are free to use those keybindings wherever you want :smile:

If you still don’t understand why your keybindings didn’t override the ones provided by Atom, it’s because the selectors (the third column in your image) use the CSS specificity mechanism to determine which element should listen to your keybinding. This article provides some insight into the specificity mechanism. Hope this helps :smile:


#10

I understand the CSS specificity mechanism, and I’ve mapped all my keybindings according to this principle but I’m still confused with ctrl-k.

This is how I unset all ctrl-k shortcuts:

'body':
  'ctrl-k ctrl-alt-w': 'unset!'
  'ctrl-k ctrl-down': 'unset!'
  'ctrl-k ctrl-left': 'unset!'
  'ctrl-k ctrl-right': 'unset!'
  'ctrl-k ctrl-n': 'unset!'
  'ctrl-k ctrl-p': 'unset!'
  'ctrl-k ctrl-w': 'unset!'
  'ctrl-k down': 'unset!'
  'ctrl-k left': 'unset!'
  'ctrl-k right': 'unset!'
  'ctrl-k up': 'unset!'
'atom-workspace atom-text-editor:not([mini])':
  'ctrl-k ctrl-0': 'unset!'
  'ctrl-k ctrl-1': 'unset!'
  'ctrl-k ctrl-2': 'unset!'
  'ctrl-k ctrl-3': 'unset!'
  'ctrl-k ctrl-4': 'unset!'
  'ctrl-k ctrl-5': 'unset!'
  'ctrl-k ctrl-6': 'unset!'
  'ctrl-k ctrl-7': 'unset!'
  'ctrl-k ctrl-8': 'unset!'
  'ctrl-k ctrl-9': 'unset!'
'.platform-win32, .platform-linux':
  'ctrl-k ctrl-b': 'unset!'
'.platform-win32 atom-text-editor, .platform-linux atom-text-editor':
  'ctrl-k ctrl-d': 'unset!'
'atom-workspace atom-text-editor':
  'ctrl-k ctrl-l': 'unset!'
  'ctrl-k ctrl-u': 'unset!'
'.platform-win32 .tree-view, .platform-linux .tree-view':
  'ctrl-k down': 'unset!'
  'ctrl-k up': 'unset!'
  'ctrl-k right': 'unset!'
  'ctrl-k left': 'unset!'
  'ctrl-k h': 'unset!'
  'ctrl-k j': 'unset!'
  'ctrl-k k': 'unset!'
  'ctrl-k l': 'unset!'

… So as you can see, I’m using all possible selectors (Taken from settings > keybindings & keybinding resolver), but even with that I’m still facing the same problem.


UPDATE:

Ok, I don’t know how but now without removing any ctrl-k shortcut (No unset!) and using a simple:

'atom-text-editor.vim-mode:not(.insert-mode)':
      'ctrl-k': 'window:focus-pane-above'

The command works with Ctrl-k k :confused:

I really like the keybinding system of Atom, it permits me to customize my mapping the way I want (It’s now the same as 90% of my vim mappings :smile: ). The only negative point is the use by default of prefix keys like ctrl-k, its really a pain in the ass to remap them.

Anyway, even if it’s a little tricky my main problem is solved, so you can close the discussion.
Thanks.


#11

Ah, I’m sorry, the formatting of your keymap.cson was weird last time I checked, It made me think you applied all keybindings to the body selector… Anyway, glad to hear you could solve your problems :smile: Yeah I also like Atom’s keybinding system, it’s very flexible, but it comes at a cost of confusion and/or frustration sometimes :stuck_out_tongue:


#12

Yeah my fault sorry, I’ve edited my messages. Discuss remove break lines in a code block when there are no empty line(s) before or after this block.


#13

I haven’t read all thread though, use @aki77 's

package, it support disable keymaps with specified prefix like ctrl-k


Can I unbind all ctrl-k shortcuts at once?
#14

Thanks, I’ve already used it, but it doesn’t help me. It give possibility to disable all Ctrl-k keybindings but no possibility to assign a new command to ctrl-k.


#15

Oh, surprised. You mean disable-keybindings disable keymap defined in user’s keymap.cson?
If so you’d better to create issue to exclude keymap defiined in keymap.cson from disable-list even if prefix matched.


#16

[quote=“t9md, post:15, topic:19217”]
You mean disable-keybindings disable keymap defined in user’s keymap.cson?
[/quote]Yes, last time I’ve used it (More than one month).

I’ll take another look, maybe they have improved the plugin somehow.


UPDATE

I just enabled the plugin again and this is just awesome! It works as expected, no extra k and no latency :smiley:

Thanks for reminding me about this wonderful package.


#17

@KabbAmine thanks for sharing your key bindings. ost of them were very useful for my atom setup.