Clear all currently defined vim macros
I have a vim macro that I keep mistyping, usually when I'm trying to save something so I do it quickly and I can't work out what keys I pressed. It is annoying as it pastes some irrelevant bash code into my file so I have to undo the erroneous pasting which also undos the last thing I typed that I do want.
I was looking for a way to either list the currently defined m开发者_如何学JAVAacros (so I can redefine the offending one), or a way to clear out them completely. I only use macros in the very short term so I don't mind losing them all.
Cheers
Macros
What is mostly called a macro in vim is initiated with @ and a letter. It executes the contents of a register with the said letter as its name.
List the register contents
:reg
You can clear the register a with
:let @a = ''
Sometimes mappings or abbreviations are confused for macros, therefore here is some information about them.
List mappings
all mappings
:map
all mappings that start with \
:map \
normal mode
:nmap
insert mode
:imap
visual mode
:vmap
command mode
:cmap
List abbreviations
all abbreviations
:abbr
all abbreviations starting with email
:abbr email
insert mode
:iabbr
command mode
:cabbr
You can use :verbose
before the previous commands to get more info about where the mapping/abbreviation was last set, as in :verbose nmap
. These commands also show all the mappings that have been set by plugins and other configuration files.
Removing a mapping/abbreviation
(only a couple of modes listed here, you should be able to remove one just for a certain mode just like with the listing commands above.)
insert mode, remove a mapping that is defined as \:
:iunmap \\
normal mode:
:nunmap \\
remove an abbreviation defined as email:
:unabbr email
insert mode:
:iunabbr email
Clear mappings/abbreviations
I wouldn't recommend clearing all mappings/abbreviations since you would lose everything your plugins have mapped/abbreviated. However, you can clear mappings by putting the letter c after the above listing command, as in :imapc
to clear insert mode mappings. Abbreviations can be cleared with :abclear
, or just for insert mode :iabclear
and just for command mode :cabclear
.
To clear a single macro - record over it - with nothing.
For your situation in normal mode you'd just type "qwq".
- q to begin to record a macro
- w to set the buffer space to w
- q again to save the (now empty) macro
Verify with :reg[ister] w
This is only slightly quicker than :let @w = '' but for myself is easier to remember.
精彩评论