tags:

views:

65

answers:

1

Hi everyone

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

+3  A: 

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.

Heikki Naski
Thanks for this, it was a macro in the end (@w which could easily get typed when saving!). I've cleared it now, cheers
Simon Walker
Just out of curiosity, how exactly do you save if you might mistype @w? And sorry for assuming you meant something else, it's just that even vim help guides you to key-mapping section if you look for :h macro. I edited the reply so that the macro part is at the start of the answer.
Heikki Naski
I save in vim with :w, how do you save a file? As you found, the vim help directed me to the wrong place, hence the question.
Simon Walker
I just found it odd since I have extremely rarely typed @ by accident even though I do mistype lots of other characters.While coding, I usually have a mapping for <BS>w that saves the file and runs a syntax checker on it.
Heikki Naski
well I'm on a british keyboard so the @ key is right next to the : key
Simon Walker