Clear Annoying Vim Macros

Recording a macro in vim involves pressing q followed by a letter in visual mode. Next time you press the letter it will run the recording. Handy, but not so great when you accidentally store something in w and then press it when you really meant to save.

The quickest way around this is to press qwq in visual mode. This just records an empty macro for register w.

You can see what’s been recorded by running the :reg command. It’s often possible to work out what it is that you’re accidentally running by looking at the listing.

Macros can be wiped in a more manual way by running :let @w=''. (Replace @w with the register that you corrupted).

Various registers are used by vim to implement the likes of yank so it’s dangerous to arbitrarily clear all the macros, however a simple vimscript function could clear all the alphabetical registers which should be safe.

Advertisements
Clear Annoying Vim Macros

Meaning of Special Characters in Vim

You will often see characters like “^@” and “^M” in files opened by vim, but it’s not well documented how to find what they actually mean.

These are called “digraphs” and, fortunately, the full list of these are available in the vim documentation.

http://vimdoc.sourceforge.net/htmldoc/digraph.html#digraph-table

To insert digraphs, you can use CTRL+K in insert mode and the two-letter alias for the digraph. CTRL+I will let you insert a literal character (e.g. a tab if you have those turned off). CTRL+V will insert a character by numeric value for example CTRL+V x 41 will insert a capital ‘A’.

These commands can be particularly useful in substitutions for junk characters, but if you need to type foreign characters it can be easier to set digraph and use backspace to add the accent to a character you just typed.

Meaning of Special Characters in Vim