Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to display a macro list similar to displaying your mappings in Vim?

Tags:

vim

vi

macros

I know there is a way to list mappings via :map (or :imap, :cmap, etc.), but I can't find a way to list macros I have stored in my vimrc file (as in let @a = 'blahblah').

Is there a way to do this without having to manually looking inside it (via :split [myvimrcfile] or whatever way)?

Also, if it is possible, is there a way to attach some sort of documentation that would display with the macro to explain what it is for? I have a handful that I use quite a bit, but about 6 weeks apart. It would be nice to just quickly list them along with a comment that tells me what the macro does (or even just a name so I make sure I use the right one).

Thanks

like image 546
Jason Down Avatar asked Nov 19 '09 19:11

Jason Down


People also ask

How do I create a macro in vim?

To record a macro and save it to a register, type the key q followed by a letter from a to z that represents the register to save the macro, followed by all commands you want to record, and then type the key q again to stop the recording.

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.

What is silent key in Vim?

<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.

What is control in Vim?

Because of Vim's modes, there is not a lot of holding down the Ctrl key while pressing another key. However ,in insert (or replace) mode, Ctrl + R will let you paste a register, and Ctrl + V lets you insert any character literally. Ctrl + W deletes a word, and Ctrl + H backspaces a letter.


2 Answers

In vim, the macros are just stored in registers. You can recall the content of any register and execute it as a macro (which is what the @ does). To see a list of what is in your registers, use :reg.

like image 172
jheddings Avatar answered Sep 21 '22 15:09

jheddings


You can see the contents of all the registers using the

:reg 

command. Or an argument string like this

:reg ahx 

will show you the contents of registers a, h, and x.

That way you can at least see what sequence of commands will be run and hopefully that will be clear enough for you to tell one from another.

The registers simply contain text. You can paste the command sequence in as text or you can copy text into a register and then run it as a command, depending on how you access the register.

I have not found any direct way to edit the contents of a register, but you can paste it into the file, edit it, and then save it back to the same register.

IHTH.

like image 26
August Mohr Avatar answered Sep 21 '22 15:09

August Mohr