t9md / atom-vim-mode-plus

vim-mode improved
https://atom.io/packages/vim-mode-plus
MIT License
1.4k stars 111 forks source link

How to re-map subword movement? #960

Closed eyaleizenberg closed 6 years ago

eyaleizenberg commented 6 years ago

I want to remap space-w, space-e, space-b, space-d, space-D for example to do the appropriate subword actions (move to next subword, end of next subword, back subword, delete subword, delete subword back).

However, I can't get the mappings to work for me? Can you please post examples of the correct key mappings for this?

Thanks a lot! This package is a life saviour!

Check list

t9md commented 6 years ago

Here is answer and how you can do by yourself next time.

HowTO and Answer

  1. Find where similar command are defined in default keymap.

In this case, find w here. https://github.com/t9md/atom-vim-mode-plus/blob/master/keymaps/vim-mode-plus.cson#L66

  1. define keymap in your keymap.cson with same keymap scope.

You can open your keymap by invoking Open Your Keymap command from command-palette.

'atom-text-editor.vim-mode-plus:not(.insert-mode)':
  'space w': 'vim-mode-plus:move-to-next-word'
  'space b': 'vim-mode-plus:move-to-previous-subword'
  'space e': 'vim-mode-plus:move-to-end-of-subword'

For space d to delete subword mapping, you cannot do it unless you define your own custom operator or hack keymap system.

But you can map d ANYKEY to delete subword.

With following example, you can d x to delete subword TextObject.

'atom-text-editor.vim-mode-plus.operator-pending-mode.delete-pending':
  'd x': 'vim-mode-plus:inner-subword'

Btw, vim-mode-plus have following default keymap.

So you can do d i d to delete subword without any custom keymap.

References.

http://flight-manual.atom.io/behind-atom/sections/keymaps-in-depth/ https://github.com/t9md/atom-vim-mode-plus/blob/master/keymaps/vim-mode-plus.cson https://github.com/t9md/dotfiles

eyaleizenberg commented 6 years ago

@t9md Thanks a lot! The d i d is really useful. Thanks!

t9md commented 6 years ago

Btw, vmp have shorthand keystroke(= one-keystroke text-object shorthand).

https://github.com/t9md/atom-vim-mode-plus/blob/0aac87e6ec6683f23b8a0fa539f19811021c8795/keymaps/vim-mode-plus.cson#L490-L496

So you can type

You can swap y(yank) operator with any other operator like c p, c ,, c d.

But d d doesn't work as delete subword. since y y, d d, c c have have special meaning, so one-key shorthand keymap is disabled in conflicting case like this.

These keymaps are available only in operator-pending mode(in other words, it's not available in visual-mode).

t9md commented 6 years ago

If you want use c c to change word too. You can enable it via configuration keymapCCToChangeInnerSmartWord.