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 macros (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
:regYou 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
:mapall mappings that start with \
:map \normal mode
:nmapinsert mode
:imapvisual mode
:vmapcommand mode
:cmapList abbreviations
all abbreviations
:abbrall abbreviations starting with email
:abbr emailinsert mode
:iabbrcommand mode
:cabbrYou can use
:verbosebefore 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 emailinsert mode:
:iunabbr emailClear 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
:imapcto clear insert mode mappings. Abbreviations can be cleared with:abclear, or just for insert mode:iabclearand just for command mode:cabclear.