Reputation: 53027
I'd like to change the prefix key of every text object command. For instance:
aw -> qw
as -> qs
ap -> qp
and so on.
I have tried creating a very long list of xnoremap
and onoremap
that change one text object command per remap, but this is a very bad solution.
Is there a way I can do this easily?
Also, I would like all the old commands to be unmapped so that they don't interfere.
Upvotes: 2
Views: 296
Reputation: 172520
I'd utilize a for
loop to avoid the repetition:
for textObject in ['w', 's', 'p']
execute printf('xnoremap q%s a%s', textObject, textObject)
execute printf('onoremap q%s a%s', textObject, textObject)
" Remove the original commands.
execute printf('xnoremap a%s <Nop>', textObject)
execute printf('onoremap a%s <Nop>', textObject)
endfor
Upvotes: 2
Reputation: 5112
Other editors may have a model of functions and key-bindings, but vim does not. Vim has built-in commands and user-defined mappings. You can clear the latter, but there is no way to "unmap" a built-in command.
You could use the 'langmap'
option to swap the meaning of a and q. This is very similar to one of the examples given under :help 'langmap'
:
:set langmap=aq,qa
Read the help to see exactly what this does and does not affect. Of course, this means that you will have to use a to start or end recording a macro and q to append. You can try to undo that with
:nnoremap a a
:nnoremap q q
but I am not sure how well that will work.
Upvotes: 0
Reputation: 309
Why do you want to change text object command?Do the default have any problems?If you have to do so,I think you can do like this:
nnoremap dqw daw
nnoremap dqs das
nnoremap dqp dap
...
Upvotes: 0