tags:

views:

1167

answers:

5
+1  A: 

Type q: to get into history editing mode in a new buffer. Then edit the last line of the buffer and press enter to execute it.

Johannes Hoff
Yes, thanks. So difficult starting a command with something other than ":"!
Johannes Hoff
+2  A: 

Typically, you would do that with mouse selecting (perhaps Ctrl+Ins or Ctrl+C after selecting) and then, when in the command/search line, middle-clicking (or Shift+Ins or Ctrl+V).

Another way, is to write your command/search line in the text buffer with all the editing available in text buffers, starting with : and all, then, on the line, do:

"add@a

which will store the whole command line in buffer a, and then execute it. It won't be stored in the command history, though.

Try creating the following line in the text buffer as an example for the keypresses above:

:%s/$maximumTotalAllowedAfterFinish/$minimumTotalAllowedAfterFinish/g

Finally, you can enter q: to enter history editing in a text buffer.

ΤΖΩΤΖΙΟΥ
+1 for mentioning the mouse
Cristian Ciupitu
+14  A: 

You can insert the contents of a numbered or named register by typing CTRL-R {0-9a-z"%#:-=.}. By typing CTRL-R CTRL-W you can paste the current word under the cursor. See

:he cmdline-editing

for more information.

WMR
+3  A: 

Copy it as normal, then do control-r " to paste. There are lots of other control-r shortcuts (Eg, a calculator, current filename, clipboard contents). Type :help c_ to see the full list.

Ned
+3  A: 

Or create the command in a vim buffer , e.g. type it in the buffer:

s/foo/bar/gci

And copy it to a named register, with "ayy (if the cursor is on that line!).

Now you can execute the contents of the "a" register from Vim's Ex command line with:

:[OPTIONAL_RANGE]@a

I use it all the time.

Zsolt Botykai
your "ayy" either is quoted (and therefore incorrect) or it's not (and therefore there's an erroneous " at the end)
ΤΖΩΤΖΙΟΥ
Thanks for the correction.
Zsolt Botykai