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