Allow super granular scope based keybinding
t9md opened this issue · 1 comments
This is experiment but idea is very simple.
Atom provides scope based keybinding.
To create scope, just set css class for editorElement.
So
Create very short life time scope to when specific operator is running.
- e. g. keymap only activated only while waiting for target motion/text-object for
yank
.
Here, following keymap is only mapped only when Yank
, or Delete
operation is waiting for tareget.
So you can yank or delete paragraph by yp
, dp
, shorter than yip
, dip
.
But other operator-pending-mode
keybinding is not contaminated by this keymap.
This is the direct advantage of this granular narrowed keymap scope.
'atom-text-editor.vim-mode-plus.yank, atom-text-editor.vim-mode-plus.delete':
'p': 'vim-mode-plus:inner-paragraph'
The change is just set css class while operation start running, then remove this css class on operation finished.
CSS class to be set is comand name without vim-mode-plus
prefix.
So for vim-mode-plus:yank
command, yank
is scope to be set.
CSS class to be set is "command name without vim-mode-plus
prefix" + "-pending".
So for vim-mode-plus:yank
command, scope should be yank-pending
.
This class is set only when command was not complete like target requiring operator(d
, y
) or input requiring motion(m
, /
).
Here is my example.
- yank/delete paragraph by
yp
,dp
- yank/delete commented area by
y/
,d/
- uncomment consecutive commented area by
g//
(g/
is mapped totoggle-line-comments
operator) - toggle comment for this paragraph by
g/p
'atom-text-editor.vim-mode-plus.yank-pending, atom-text-editor.vim-mode-plus.delete-pending':
'p': 'vim-mode-plus:inner-paragraph'
'/': 'vim-mode-plus:inner-comment'
'atom-text-editor.vim-mode-plus.toggle-line-comments-pending':
'/': 'vim-mode-plus:inner-comment'
'p': 'vim-mode-plus:inner-paragraph'