VIM: How to get the last ex command you used

copy/pastekeyboard shortcutstext-editorsvim

I find that sometimes I write a really long ex mode command that do lots of stuff. They are sort of "mini-scripts" that I write in the text editor then I start ex mode and copy them into the ex line and execute. But then I always end up editing in the ex mode and then I find it difficult to get the changes i did in ex mode back to my text editing session.

Using the keyboard, how do you copy the last ex command you used and paste it into your text editor?

(Note: This is sort of the opposite of this question "how do I copy/paste in vim ex mode" where the user asks "how do you copy from the text editor and paste INTO the ex mode?". My question is the opposite because I wish to copy from the ex mode and paste into my text editor.)

Best Answer

The : register contains the last :-command (ex command) you ran, so you can simply type the command ":p (with the double quote) to paste that register into the current buffer. See:

:help registers
:help ":

Note that there are registers for the last search, the current buffer's name, etc.

Related Question