Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
I have a kludge that does this... but it requires the mouse to select... the gvim pull down menu to copy... and if the ex line is two lines the paste has a new line which is annoying. (but more annoying is the fact that I am using the mouse and the gui to copy/paste...). –  Trevor Boyd Smith Jan 8 '11 at 16:18

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer

Try the q: command. (That's two characters, first q and then :.) This is a normal mode command that will open up your ex-command history in a special Vim buffer. You can review the history, yank anything you want just as always, and/or edit a line and press <enter> on it to execute it.

share|improve this answer
    
Just be careful not to type :q instead, which my muscle memory tries to force on me! –  frabjous Jan 8 '11 at 17:27
2  
q: works from normal mode. If you're already in command-line (ex) mode, type Ctrl-F to open that command-line window. –  garyjohn Jan 8 '11 at 18:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.