Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear all currently defined vim macros

Tags:

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 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

like image 783
Simon Walker Avatar asked Apr 22 '10 09:04

Simon Walker


People also ask

How do I delete a macro in vim?

Press Esc to return to normal mode. Type "ayy to yank the modified macro into the a register. Type dd to delete the pasted register from the file you are editing.

Where does vim store macros?

As you yank , delete , or create macros in vim, it automatically stores text into these registers. When you hit p paste it's simply pasting in the default register. You can also paste in any other register by hitting "qp where q is the register that you want to paste in.

Do vim macros persist?

6) actually persists macros and named buffers automatically (by default, although I haven't looked for a way of turning this behavior off). Closing a Vim session will update the ~/. viminfo file with any named buffers / macros.

How do I delete a register in Vim?

vim has a unnamed (or default) register that can be accessed with "" . Any text that you delete (with d , c , s or x ) or yank (with y ) will be placed there, and that's what vim uses to p aste, when no explicit register is given. A simple p is the same thing as doing ""p .


1 Answers

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.

like image 71
Heikki Naski Avatar answered Oct 06 '22 01:10

Heikki Naski